Skip to content
balauru edited this page Jul 30, 2012 · 1 revision

In an online gaming tournament, each team has competed against every other team exactly once, and each of the matches had exactly one winner and one loser. We want to create a sequence a_1, a_2, ..., a_n that fulfills the following property: for every 1 <= i < n, ai won against a(i+1). In other words, each team in the sequence won against the next team in the sequence (except for the last team, of course).

Write a program such that given the outcomes of matches, finds such a sequence if possible, or says that it's not possible.

Input

First line of input is a single integer T (1 <= T <= 10) which denotes number of testcases. T testcases follow.

First line of each testcase is a single integer N (1 <= N <= 1000) denoting number of teams in the tournament. In each of next N lines there is a string of length N consisting of 1's and 0's. If j'th character at i'th row is 1, it means that team i has won against team j, and if this character is 0 it means that team j has won. The diagonal of the matrix given is always 0, but of course it doesn't mean anything since no team plays against itself. It's also guaranteed that if i wins against j, then j loses against i.

Output

Print the output of each test-case in a single line. If there exists a sequence as described in the problem statement, print "Yes" followed by a single space, followed by a space separated list of the 0-based index of teams in sequence. There may be more than one valid sequence; you may print any of them. If the sequence doesn't exist, simply print "No".

Sample Input

1
4
0111
0011
0001
0000

Sample Output

Yes 0 1 2 3

Clone this wiki locally