#P7953. Link with Limit

Link with Limit

Link with Limit

Problem Description

Link has a function f(x)f(x), where xx and f(x)f(x) are both integers in [1,n][1,n]. Let fn(x)=f(fn1(x))f_n(x)=f(f_{n-1}(x)) and f1(x)=f(x)f_1(x) = f(x), he define the power of a number xx as:

$$g(x) = \lim \limits_{n \to + \infty} \frac{1}{n} \sum_{i=1}^{n} f_i(x) $$

He wants to know whether xx has the same power for all x[1,n]x \in [1,n].

Input

The input consists of multiple test cases. The first line contains an integer TT (1T1001 \leq T \leq 100) -- the number of test cases. For each test case: In the first line, there is an integer nn (1n1051 \leq n \leq 10^5). In the second line, there are nn integers, the ii-th integer shows the value of f(i)f(i) (1f(i)n1 \leq f(i) \leq n). It is guaranteed that the sum of nn over all test cases will not exceed 10610^6.

Output

For each test case, output 'YES' if all xx have the same power. Otherwise, output 'NO'.

Sample Input

2

2

1 2

2

1 1

Sample Output

NO

YES

Source

2021“MINIEYE杯”中国大学生算法设计超级联赛(7)