CF1747B.BAN BAN

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

BAN BAN

You are given an integer nn.

Let's define s(n)s(n) as the string "BAN" concatenated nn times. For example, s(1)s(1) = "BAN", s(3)s(3) = "BANBANBAN". Note that the length of the string s(n)s(n) is equal to 3n3n.

Consider s(n)s(n). You can perform the following operation on s(n)s(n) any number of times (possibly zero):

  • Select any two distinct indices ii and jj (1i,j3n,ij)(1 \leq i, j \leq 3n, i \ne j).
  • Then, swap s(n)is(n)_i and s(n)js(n)_j.

You want the string "BAN" to not appear in s(n)s(n) as a subsequence. What's the smallest number of operations you have to do to achieve this? Also, find one such shortest sequence of operations.

A string aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1t100)(1 \leq t \leq 100)  — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single integer nn (1n100)(1 \leq n \leq 100).

Output

For each test case, in the first line output mm (0m1050 \le m \le 10^5) — the minimum number of operations required. It's guaranteed that the objective is always achievable in at most 10510^5 operations under the constraints of the problem.

Then, output mm lines. The kk-th of these lines should contain two integers iki_k, jkj_k (1ik,jk3n,ikjk)(1\leq i_k, j_k \leq 3n, i_k \ne j_k) denoting that you want to swap characters at indices iki_k and jkj_k at the kk-th operation.

After all mm operations, "BAN" must not appear in s(n)s(n) as a subsequence.

If there are multiple possible answers, output any.

Note

In the first testcase, s(1)=s(1) = "BAN", we can swap s(1)1s(1)_1 and s(1)2s(1)_2, converting s(1)s(1) to "ABN", which does not contain "BAN" as a subsequence.

In the second testcase, s(2)=s(2) = "BANBAN", we can swap s(2)2s(2)_2 and s(2)6s(2)_6, converting s(2)s(2) to "BNNBAA", which does not contain "BAN" as a subsequence.

Samples

2
1
2
1
1 2
1
2 6

在线编程 IDE

建议全屏模式获得最佳体验