Algebra is Awesome
시간 제한1.5초메모리 제한512 MB
수열의 각 순열에 대해, 같은 순환 부분군을 생성하는(같은 거듭제곱 집합을 갖는) 앞선 순열의 개수를 센다.
문제
Every permutation can be composed with itself, which means . More generally, for positive , and is an identity permutation. For a permutation , the set of all its compositions is called , which means .
You are given an -element sequence of -element permutations . For each , find the number of such that .
입력
The first line of input contains a single integer , the number of test cases. The descriptions of the test cases follow.
The first line of each test case consists of two integers and (, ).
In each of the next lines, you are given a pemutation as a sequence of positive distinct integers ().
출력
For each test case, print numbers each on a separate line: how many different 's satisfy the given condition.