CF BUDDY
← Problems·

1903B · StORage room

1200 · bitmasks, brute force, constructive algorithms

Problem: In Cyprus, the weather is pretty hot. Thus, Theofanis saw this as an opportunity to create an ice cream company.

He keeps the ice cream safe from other ice cream producers by locking it inside big storage rooms. However, he forgot the password. Luckily, the lock has a special feature for forgetful people!

It gives you a table MM with nn rows and nn columns of non-negative integers, and to open the lock, you need to find an array aa of nn elements such that:

  • 0ai<2300 \le a_i < 2^{30}, and
  • Mi,j=aiajM_{i,j} = a_i | a_j for all iji \neq j, where | denotes the bitwise OR operation.

The lock has a bug, and sometimes it gives tables without any solutions. In that case, the ice cream will remain frozen for the rest of eternity.

Can you find an array to open the lock?

Input Format: The first line contains a single integer tt (1t1031 \le t \le 10^{3}) — the number of test cases.

The first line of each test case contains a single integer nn (1n1031 \le n \le 10^{3}) — the size of the hidden array.

The next nn lines describe the rows of MM, line ii contains the table values Mi,1,Mi,2,,Mi,nM_{i,1}, M_{i,2}, \ldots, M_{i,n} (0Mi,j<2300 \le M_{i,j} < 2^{30}).

It is guaranteed that Mi,i=0M_{i,i} = 0 and Mi,j=Mj,iM_{i,j} = M_{j,i} for all 1i,jn1 \le i,j \le n.

It is also guaranteed that the sum of nn over all test cases does not exceed 10310^{3}.

Output Format: For each test case, if there is a solution print YES and an array that satisfies the property, otherwise print NO.

If there are multiple solutions, print any of them.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Sample Cases

Case 1

Input

4
1
0
4
0 3 3 5
3 0 3 7
3 3 0 7
5 7 7 0
5
0 7 7 5 5
7 0 3 2 6
7 3 0 3 7
5 2 3 0 4
5 6 7 4 0
3
0 0 1
0 0 0
1 0 0

Output

YES
7
YES
1 3 2 5 
YES
5 2 3 0 4
NO

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback