Every permutation σ can be composed with itself, which means σ2=σ∘σ. More generally, for positive k, σk=σ∘σk−1 and σ0 is an identity permutation. For a permutation σ, the set of all its compositions is called D(σ), which means D(σ)=σk:k∈N.
You are given an m-element sequence of n-element permutations σ_1,σ_2,…,σ_m. For each i, find the number of j<i such that D(σ_i)=D(σ_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≤n≤102, 1≤m≤104).
In each of the next m lines, you are given a pemutation as a sequence of n positive distinct integers a_1,a_2,…,a_n (1≤a_i≤n).
For each test case, print m numbers each on a separate line: how many different j's satisfy the given condition.