시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1.5 초 | 512 MB | 37 | 9 | 7 | 21.875% |
Every permutation $\sigma$ can be composed with itself, which means $\sigma^{2} = \sigma \circ \sigma$. More generally, for positive $k$, $\sigma^{k} = \sigma \circ \sigma^{k - 1}$ and $\sigma^{0}$ is an identity permutation. For a permutation $\sigma$, the set of all its compositions is called $D(\sigma)$, which means $D(\sigma) = \{\sigma^{k} : k \in \mathbf{N}\}$.
You are given an $m$-element sequence of $n$-element permutations $\sigma_{1}, \sigma_{2}, \ldots, \sigma_{m}$. For each $i$, find the number of $j < i$ such that $D(\sigma_{i}) = D(\sigma_{j})$.
The first line of input contains a single integer $z$, the number of test cases. The descriptions of the test cases follow.
The first line of each test case consists of two integers $n$ and $m$ ($1 \leq n \leq 10^2$, $1 \leq m \leq 10^4$).
In each of the next $m$ lines, you are given a pemutation as a sequence of $n$ positive distinct integers $a_{1}, a_{2}, \ldots, a_{n}$ ($1 \leq a_{i} \leq n$).
For each test case, print $m$ numbers each on a separate line: how many different $j$'s satisfy the given condition.
1 3 3 2 3 1 3 1 2 1 2 3
0 1 0