AquaMoon and Permutations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
Articles
Cirno has prepared arrays of length each. Each array is a permutation of integers from to . These arrays are special: for all , if we take the -th element of each array and form another array of length with these elements, the resultant array is also a permutation of integers from to . In the other words, if you put these arrays under each other to form a matrix with rows and nn columns, this matrix is a Latin square.
Afterwards, Cirno added additional arrays, each array is a permutation of integers from 11 to . For all , there exists at least one position , such that for the -th array and the -th array, the -th element of both arrays is the same. Notice that the arrays indexed from to don’t have to form a Latin square.
Also, Cirno made sure that for all arrays, no two arrays are completely equal, i. e. for all pair of indices , there exists at least one position , such that the -th elements of the -th and -th array are different.
Finally, Cirno arbitrarily changed the order of arrays.
AquaMoon calls a subset of all arrays of size good if these arrays from a Latin square.
AquaMoon wants to know how many good subsets exist. Because this number may be particularly large, find it modulo . Also, she wants to find any good subset. Can you help her?
Input
The input consists of multiple test cases. The first line contains a single integer — the number of test cases.
The first line of each test case contains a single integer .
Then lines followed. The -th of these lines contains integers, representing the -th array.
It is guaranteed, that the sum of over all test cases does not exceed .
Output
For each test case print two lines.
In the first line, print the number of good subsets by modulo .
In the second line, print indices from to — indices of the arrays that form a good subset (you can print them in any order). If there are several possible answers — print any of them.
Example
input
1 | 3 |
output
1 | 1 |
Node
In the first test case, the number of good subsets is 1. The only such subset is the set of arrays with indices 1, 2, 3, 4, 5, 6, 7.
In the second test case, the number of good subsets is 2. They are 1, 3, 5, 6, 10 or 2, 4, 7, 8, 9.
Tutorial
Among all the arrays not be chosen, if an array have a number which appears exactly once at its column, that the array must belong to the n original arrays. So, we can choose the array and delete all arrays have at least one same bit with it.
If there not exists such an array discribed above, according to the Pigeonhole Principle, all numbers of the unchosen arrays must appear exactly twice on their columns. It means either the original arrays or the additional arrays can form a correct latin square. So, it’s correct to choose any one of the unchosen array and delete all arrays have at least one same bit with it. Meanwhile, we need to multiply the number of solutions by 2.
We need to repeat the above operations, until we have chosen n arrays.
code
1 |
|