Algebra is Awesome

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

문제

Every permutation σ\sigma can be composed with itself, which means σ2=σσ\sigma^{2} = \sigma \circ \sigma. More generally, for positive kk, σk=σσk1\sigma^{k} = \sigma \circ \sigma^{k - 1} and σ0\sigma^{0} is an identity permutation. For a permutation σ\sigma, the set of all its compositions is called D(σ)D(\sigma), which means D(σ)=σk:kND(\sigma) = \\{\sigma^{k} : k \in \mathbf{N}\\}.

You are given an mm-element sequence of nn-element permutations σ_1,σ_2,,σ_m\sigma\_{1}, \sigma\_{2}, \ldots, \sigma\_{m}. For each ii, find the number of j<ij < i such that D(σ_i)=D(σ_j)D(\sigma\_{i}) = D(\sigma\_{j}).

입력

The first line of input contains a single integer zz, the number of test cases. The descriptions of the test cases follow.

The first line of each test case consists of two integers nn and mm (1n1021 \leq n \leq 10^2, 1m1041 \leq m \leq 10^4).

In each of the next mm lines, you are given a pemutation as a sequence of nn positive distinct integers a_1,a_2,,a_na\_{1}, a\_{2}, \ldots, a\_{n} (1a_in1 \leq a\_{i} \leq n).

출력

For each test case, print mm numbers each on a separate line: how many different jj's satisfy the given condition.