#P1945E. Binary Search

    ID: 10460 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>binary searchconstructive algorithmsgreedy*1700

Binary Search

Description

Anton got bored during the hike and wanted to solve something. He asked Kirill if he had any new problems, and of course, Kirill had one.

You are given a permutation pp of size nn, and a number xx that needs to be found. A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

You decided that you are a cool programmer, so you will use an advanced algorithm for the search — binary search. However, you forgot that for binary search, the array must be sorted.

You did not give up and decided to apply this algorithm anyway, and in order to get the correct answer, you can perform the following operation no more than 22 times before running the algorithm: choose the indices ii, jj (1i,jn1\le i, j \le n) and swap the elements at positions ii and jj.

After that, the binary search is performed. At the beginning of the algorithm, two variables l=1l = 1 and r=n+1r = n + 1 are declared. Then the following loop is executed:

  1. If rl=1r - l = 1, end the loop
  2. m=r+l2m = \lfloor \frac{r + l}{2} \rfloor
  3. If pmxp_m \le x, assign l=ml = m, otherwise r=mr = m.

The goal is to rearrange the numbers in the permutation before the algorithm so that after the algorithm is executed, plp_l is equal to xx. It can be shown that 22 operations are always sufficient.

Each test consists of multiple test cases. The first line contains a single integer tt (1t21041 \le t \le 2\cdot 10^4) — the number of test cases. Then follow the descriptions of the test cases.

The first line of each test case contains two integers nn and xx (1xn21051 \le x \le n \le 2\cdot 10^5) — the length of the permutation and the number to be found.

The second line contains the permutation pp separated by spaces (1pin1 \le p_i \le n).

It is guaranteed that the sum of the values of nn for all test cases does not exceed 21052\cdot 10^5.

For each test case, output an integer kk (0k20 \le k \le 2) on the first line — the number of operations performed by you. In the next kk lines, output 22 integers ii, jj (1i,jn1 \le i, j \le n) separated by a space, indicating that you are swapping the elements at positions ii and jj.

Note that you do not need to minimize the number of operations.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1t21041 \le t \le 2\cdot 10^4) — the number of test cases. Then follow the descriptions of the test cases.

The first line of each test case contains two integers nn and xx (1xn21051 \le x \le n \le 2\cdot 10^5) — the length of the permutation and the number to be found.

The second line contains the permutation pp separated by spaces (1pin1 \le p_i \le n).

It is guaranteed that the sum of the values of nn for all test cases does not exceed 21052\cdot 10^5.

Output

For each test case, output an integer kk (0k20 \le k \le 2) on the first line — the number of operations performed by you. In the next kk lines, output 22 integers ii, jj (1i,jn1 \le i, j \le n) separated by a space, indicating that you are swapping the elements at positions ii and jj.

Note that you do not need to minimize the number of operations.

Sample Input 1

5
6 3
1 2 3 4 5 6
6 5
3 1 6 5 2 4
5 1
3 5 4 2 1
6 3
4 3 1 5 2 6
3 2
3 2 1

Sample Output 1

0
1
3 4
2
2 4
1 5
2
4 5
2 4
1
1 3