아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Algebra is Awesome

시간 제한1.5초메모리 제한512 MB

요약
수열의 각 순열에 대해, 같은 순환 부분군을 생성하는(같은 거듭제곱 집합을 갖는) 앞선 순열의 개수를 센다.
난이도

보통10점 중 7점

유형
해시맵, 수학, 정수론, 구현
정답자
아직 제출이 없습니다

문제

Every permutation σ\sigma can be composed with itself, which means σ2=σ∘σ\sigma^{2} = \sigma \circ \sigma. More generally, for positive kk, σk=σ∘σk−1\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:k∈ND(\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 (1≤n≤1021 \leq n \leq 10^2, 1≤m≤1041 \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} (1≤a_i≤n1 \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.

예제1

  1. 예제 1

    입력
    1
    3 3
    2 3 1
    3 1 2
    1 2 3
    
    예상 출력
    0
    1
    0