시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 512 MB379721.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

1
3 3
2 3 1
3 1 2
1 2 3

예제 출력 1

0
1
0