Since her creation to maintain the Tethys system, the Shorekeeper has diligently studied various algorithms under her creator's guidance. Among these, she found the Disjoint Set Union (DSU) data structure to be the most elegant. Her implementation uses the following code:
vector<int> f(n); iota(f.begin(), f.end(), 0); // initialize f[i] = i
int find(int u){ return f[u] == u ? u : f[u] = find(f[u]); } // path compression
void merge(int u, int v){ u = find(u); v = find(v); f[u] = v; }
Your task is to determine whether a given array $$$f$$$ could result from applying at most $$$n$$$ merge operations on an initially created DSU structure. The initial state uses the first code snippet above, and subsequent operations may only call the merge function.
Each test has multiple test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 4\cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$f_0,f_1,\dots,f_{n-1}$$$ ($$$0\le f_i \lt n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$4\cdot 10^5$$$.
For each test case, if a solution exists, output as follows:
; otherwise, output $$$-1$$$ in a single line.
31021 030 1 0
0 -1 1 2 0