Good and Lucky Matrices

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

This is a run-twice problem: your solution will be executed twice on each test. See the rest of the statement and the input format section for more details.

A square binary matrix is good if and only if it has an odd determinant.

A binary matrix of size n×nn \times n is lucky if and only if the greedy matching algorithm described below successfully finds a matching of size nn. The algorithm reads the matrix line-by-line, from top to bottom. On each line, if there is a 11 in a column that was never chosen before, the algorithm greedily chooses the leftmost such column.

Your task is to compare numbers of good and lucky matrices of size n×nn \times n. In order to do that, you have to produce a bijection between the smaller set and an equinumerous subset of the larger set.

입력

On each run, the first line contains an integer tt: the number of test cases. The test cases follow.

The first line of each test case contains a string "good" or "lucky" denoting the type of matrix.

The next line contains a single integer nn (1n20001 \leq n \leq 2000): the size of the matrix.

Then follow nn lines: ii-th of them contains a binary string of length exactly nn denoting the ii-th row of the matrix.

The matrices given to your program on the second run will be the exactly the same as the matrices printed by your program on the first run, in the same order.

In is guaranteed that the sum of nn over all test cases does not exceed 20002000.

출력

On each run, you have to print tt answers. Each answer should be either a single integer 1-1 printed on a separate line or a matrix of the opposite type formatted similarly to the input: a line with size nn followed by nn lines describing the rows.

The mapping produced by your program should be a bijection. In other words, all the matrices printed on the second run should correspond to preimage of the corresponding matrix on the first run. Additionally, the number of 1-1 should be not greater than the difference in the sizes of the sets.

Formally, if on the first run your answer for matrix AA of some type was matrix BB, and on the second run your answer for matrix BB of the opposite type was matrix CC, then A=CA = C must hold. Additionally, for each nn and each matrix type, let UU be the set of all n×nn \times n matrices of this type, and VV the set of n×nn \times n matrices of the other type. Then you can answer 1-1 for at most max(UV,0)\max (\lvert U \rvert - \lvert V \rvert, 0) different matrices from UU.