{"problem":{"name":"Ball Redistribution","description":{"content":"There are $N$ boxes numbered from $1$ to $N$, and $N$ balls numbered from $1$ to $N$. You have assigned Snuke the following **procedure** as homework. *   Put each ball into any box he likes. Multipl","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc068_c"},"statements":[{"statement_type":"Markdown","content":"There are $N$ boxes numbered from $1$ to $N$, and $N$ balls numbered from $1$ to $N$.\nYou have assigned Snuke the following **procedure** as homework.\n\n*   Put each ball into any box he likes. Multiple balls can be placed in the same box, and there can be boxes without balls.\n*   For $i = 1, 2, \\cdots, N$ in this order, perform the following operations.\n    *   If box $i$ contains no balls, do nothing.\n    *   If box $i$ contains balls, take all of them out and arrange them in a line **in any order he likes**. Let $k$ be the number of balls taken out, and $(x_1, x_2, \\cdots, x_k)$ be the ball numbers in the line. For each $1 \\leq j \\leq k$, put ball $x_j$ into box $x_{j+1}$. Here, $x_{k+1}$ means $x_1$. All these operations of putting balls into boxes happen simultaneously.\n\nHe claims that he has completed the homework and reports the final state to you. Specifically, he says that ball $i$ is in box $A_i$ after the procedure.\nYou doubt whether he has correctly performed the procedure. Determine whether the state he reported is a possible result of the procedure.\nThere are $T$ test cases for each input.\n\n## Constraints\n\n*   $1 \\leq T \\leq 250000$\n*   $1 \\leq N \\leq 250000$\n*   $1 \\leq A_i \\leq N$\n*   The sum of $N$ over all test cases in each input is at most $250000$.\n*   All input values are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$T$\n$case_1$\n$case_2$\n$\\vdots$\n$case_T$\n\nEach test case is given in the following format:\n\n$N$\n$A_1$ $A_2$ $\\cdots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc068_c","tags":[],"sample_group":[["5\n3\n1 1 1\n3\n2 2 2\n5\n1 2 3 4 5\n10\n8 3 8 10 1 5 3 1 6 4\n10\n1 5 1 2 4 8 8 6 7 3","Yes\nNo\nYes\nNo\nYes\n\nConsider the first test case. The following steps yield the state Snuke reported, so the answer is `Yes`.\n\n*   Put balls $1, 2, 3$ into boxes $1, 1, 2$, respectively.\n*   Take out the balls from box $1$ and arrange them as $(2, 1)$.\n    *   Put ball $2$ into box $1$.\n    *   Put ball $1$ into box $2$.\n*   Take out the balls from box $2$ and arrange them as $(1, 3)$.\n    *   Put ball $1$ into box $3$.\n    *   Put ball $3$ into box $1$.\n*   Take out the balls from box $3$ and arrange them as $(1)$.\n    *   Put ball $1$ into box $1$.\n*   Now, balls $1, 2, 3$ are all in box $1$."]],"created_at":"2026-03-03 11:01:14"}}