#P8910. [RC-06] Operation Sequence

[RC-06] Operation Sequence

Problem Description

You are given nn, and an array [a1,a2,,an+1][a_1,a_2,\dots,a_{n+1}] of length n+1n+1. Initially, ai=i (1in)a_i=i\ (1\le i\le n), and an+1=0a_{n+1}=0.

You may only perform the following type of operation, by printing a specific string:

  • Print i j: where i,ji,j are positive integers with 1i,jn+11\le i,j\le n+1, meaning assign aia_i to aja_j (i.e., set ai=aja_i=a_j).

Please cyclically shift the first nn elements of array aa to the right by KK positions. That is, after all operations you print are executed, it must satisfy:

  • For positions i (1iK)i\ (1\le i\le K), ai=nK+ia_i = n-K+i.
  • For positions i (K+1in)i\ (K+1\le i\le n), ai=iKa_i = i-K.
  • The (n+1)(n+1)-th element can be anything.

You may perform at most T=1.5nT=\lfloor1.5n\rfloor assignment operations.

If you use more than TT operations, you can still get partial points. Specifically, let your number of operations be SS:

  • If STS\le T, you get 100100 points.
  • If T<S4TT<S\le 4T, you get 5050 points.
  • If S>4TS>4T, you get 00 points.

Your score for this problem is the minimum score among all testdata in all test points.

Input Format

This problem contains multiple groups of data in a single test point.

The first line contains the number of data groups TT.

For each data group:

The first line contains two positive integers n,Kn,K.

Output Format

For each data group:

Print the number of operations k (0k4T)k\ (0\le k\le 4T) on the first line. Note that you do not need to minimize kk.

Then print kk lines, each containing two positive integers i,ji,j, representing one operation. (1i,jn+1)(1\le i,j\le n+1).

2
3 0
2 1
0
3
3 1
1 2
2 3

Hint

All data satisfy: 1T1041\le T\le 10^4, 1n1051\le n\le 10^5, 0Kn10\le K\le n-1. It is guaranteed that, within the same test point, the sum of all nn does not exceed 5×1055\times 10^5.

Translated by ChatGPT 5