{"problem":{"name":"Roller","description":{"content":"You are given sequences of positive integers of length $N$: $A=(A_1,A_2,\\dots,A_N)$ and $B=(B_1,B_2,\\dots,B_N)$. You can repeat the following operation any number of times (possibly zero). *   Choose","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc154_c"},"statements":[{"statement_type":"Markdown","content":"You are given sequences of positive integers of length $N$: $A=(A_1,A_2,\\dots,A_N)$ and $B=(B_1,B_2,\\dots,B_N)$.\nYou can repeat the following operation any number of times (possibly zero).\n\n*   Choose an integer $i$ such that $1 \\le i \\le N$ and replace $A_i$ with $A_{i+1}$.\n\nHere, regard $A_{N+1}$ as $A_1$.\nDetermine whether it is possible to make $A$ equal $B$.\nYou have $T$ test cases to solve.\n\n## Constraints\n\n*   $1 \\le T \\le 5000$\n*   $1 \\le N \\le 5000$\n*   $1 \\le A_i,B_i \\le N$\n*   For each input file, the sum of $N$ over all test cases does not exceed $5000$.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$T$\n$\\mathrm{case}_1$\n$\\mathrm{case}_2$\n$\\vdots$\n$\\mathrm{case}_T$\n\nEach test case is in the following format:\n\n$N$\n$A_1$ $A_2$ $\\dots$ $A_N$\n$B_1$ $B_2$ $\\dots$ $B_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc154_c","tags":[],"sample_group":[["3\n2\n1 2\n2 2\n4\n2 3 1 1\n2 1 1 2\n2\n1 1\n2 2","Yes\nYes\nNo\n\nIn the first test case, you can make $A$ equal $B$ as follows.\n\n*   Choose $i=1$ to replace $A_1$ with $A_2$, making $A=(2,2)$.\n\nIn the second test case, you can make $A$ equal $B$ as follows.\n\n*   Choose $i=4$ to replace $A_4$ with $A_1$, making $A=(2,3,1,2)$.\n*   Choose $i=2$ to replace $A_2$ with $A_3$, making $A=(2,1,1,2)$.\n\nIn the third test case, there is no way to make $A$ equal $B$."]],"created_at":"2026-03-03 11:01:13"}}