시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 0 | 0 | 0 | 0.000% |
Fedor works in the department of permutation transforming. Today Fedor should solve the following problem: he needs to transform the permutation $[p_1, p_2, \ldots, p_n]$ of integers $1, 2, \ldots, n$ to the permutation $[q_1, q_2, \ldots, q_n]$ using at most $n^3$ $k$-transfer operations.
Consider an array of length $n$. The $k$-transfer operation with the parameters $(a, b)$ is defined as follows: a segment of $k$ consecutive elements starting with an element at index $a$ is cut away from the array and inserted back starting with the index $b$.
More formally: consider an array $[t_1, t_2, \ldots, t_n]$ and two integers $a$ and $b$ ($1 \le a, b \le n - k + 1$). Let's create the temporary array $[r_1, r_2, \ldots, r_{n - k}]$, consisting of the numbers $[t_1, t_2, \ldots, t_{a - 1}, t_{a + k}, t_{a + k + 1}, \ldots, t_n]$. Then the result of the $k$-transfer with parameters $(a, b)$ for an array $t$ is an array, consisting of the numbers $[r_1, r_2, \ldots, r_{b - 1}, t_a, t_{a + 1}, \ldots, t_{a + k - 1}, r_b, r_{b + 1}, \ldots, r_{n - k}]$.
Fedor doesn't know how to solve the task, so he asks you to help him!
You are to solve the problem for $t$ test cases.
The first line contains a single integer $t$ ($1 \le t \le 100$) --- the number of test cases.
Each test case consists of three lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line contains $n$ different integers $p_1, p_2, \ldots, p_n$ ($1 \le p_i \le n$) --- the permutation $p$.
The third line contains $n$ different integers $q_1, q_2, \ldots, q_n$ ($1 \le q_i \le n$) --- the permutation $q$.
It's guaranteed that the sum of $n$ over all test cases doesn't exceed $100$.
Print the answer for each test case. Output your answer for a single test case in the following format.
If it's impossible to obtain a permutation $q_1, q_2, \ldots, q_n$ from a permutation $p_1, p_2, \ldots, p_n$ using $k$-transfers, print a single line consisting of the word "NO".
Otherwise, print "YES" at the first line.
The second line must contain a single integer $m$ --- the number of $k$-transfers performed to obtain the permutation $q$ from the permutation $p$ ($0 \le m \le n^3$). Note that you don't need to minimize $m$. It's guaranteed that if the permutation $q$ can be obtained from the permutation $p$ using $k$-transfers, then there is a solution that requires at most $n^3$ operations.
Each of the following $m$ lines should contain two integers --- parameters $a$ and $b$ for the corresponding $k$-transfer.
3 2 1 2 1 2 1 4 2 1 2 3 4 1 2 4 3 3 2 2 1 3 1 3 2
YES 0 NO YES 2 1 2 1 2
In the third test case there is another way to obtain a permutation $q$ from a permutation $p$ --- a single $k$-transfer with the parameters $a = 2$, $b = 1$.