This page is still under construction.

Parts of this page are still being built. What you see may change.

The K-League

Time limit1sMemory limit128 MB

Summary
For each team, decide whether remaining games can end with no team holding more wins than it.
Level

Hard8 of 10

Topics
Graph
Solved
No attempts yet

Problem

Supporters of the professional football clubs in the K-League wonder whether the team SS they cheer for can still win the championship. In other words, is it possible to decide the winners of all the remaining games so that no team finishes the season with more wins than SS? Two or more teams may share the title.

You are given, for every team ii, its current number of wins wiw_i and losses did_i, and for every pair of teams ii and jj the number ai,ja_{i,j} of games still to be played between them (where 1≤i,j≤n1 \le i, j \le n and nn is the number of teams). The teams are numbered 1,2,…,n1, 2, \dots, n. Find every team that still has a chance of winning the championship. There are no draws: every game has exactly one winner and one loser.

Input

The input contains several test cases. The first line gives the number of test cases TT.

Each test case consists of three lines:

  • The first line has the number of teams nn (1≤n≤251 \le n \le 25).
  • The second line has 2n2n integers w1 d1 w2 d2 … wn dnw_1\ d_1\ w_2\ d_2\ \dots\ w_n\ d_n, where wiw_i and did_i are the current wins and losses of team ii; each is a nonnegative integer at most 100100.
  • The third line has n2n^2 integers a1,1 a1,2 … a1,n a2,1 … an,na_{1,1}\ a_{1,2}\ \dots\ a_{1,n}\ a_{2,1}\ \dots\ a_{n,n}, where ai,ja_{i,j} is the number of remaining games between teams ii and jj; each is a nonnegative integer at most 1010. For all ii and jj, ai,j=aj,ia_{i,j} = a_{j,i}, and ai,j=0a_{i,j} = 0 when i=ji = j.

Integers on the same line are separated by one or more spaces.

Output

For each test case print exactly one line. The line lists the numbers of all teams that still have a chance of winning the championship, in increasing order, separated by single spaces.

Examples1

  1. Example 1

    Input
    3
    3
    2 0 1 1 0 2
    0 2 2 2 0 2 2 2 0
    3
    4 0 2 2 0 4
    0 1 1 1 0 1 1 1 0
    4
    0 3 3 1 1 3 3 0
    0 0 0 2 0 0 1 0 0 1 0 0 2 0 0 0
    
    Expected output
    1 2 3
    1 2
    2 4