#P1968E. Cells Arrangement

    ID: 10610 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>constructive algorithms*1600

Cells Arrangement

Description

You are given an integer nn. You choose nn cells (x1,y1),(x2,y2),,(xn,yn)(x_1,y_1), (x_2,y_2),\dots,(x_n,y_n) in the grid n×nn\times n where 1xin1\le x_i\le n and 1yin1\le y_i\le n.

Let H\mathcal{H} be the set of distinct Manhattan distances between any pair of cells. Your task is to maximize the size of H\mathcal{H}. Examples of sets and their construction are given in the notes.

If there exists more than one solution, you are allowed to output any.

Manhattan distance between cells (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2) equals x1x2+y1y2|x_1-x_2|+|y_1-y_2|.

The first line contains a single integer tt (1t501\le t\le 50) — the number of test cases.

Each of the following tt lines contains a single integer nn (2n1032\le n\le 10^3).

For each test case, output nn points which maximize the size of H\mathcal{H}. It is not necessary to output an empty line at the end of the answer for each test case.

Input

The first line contains a single integer tt (1t501\le t\le 50) — the number of test cases.

Each of the following tt lines contains a single integer nn (2n1032\le n\le 10^3).

Output

For each test case, output nn points which maximize the size of H\mathcal{H}. It is not necessary to output an empty line at the end of the answer for each test case.

Sample Input 1

5
2
3
4
5
6

Sample Output 1

1 1
1 2

2 1
2 3
3 1

1 1
1 3
4 3
4 4

1 1
1 3
1 4
2 1
5 5

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

Note

In the first testcase we have n=2n=2. One of the possible arrangements is:

The arrangement with cells located in (1,1)(1,1) and (1,2)(1,2).
In this case H={11+11,11+22,11+12}={0,0,1}={0,1}\mathcal{H}=\{|1-1|+|1-1|,|1-1|+|2-2|,|1-1|+|1-2|\}=\{0,0,1\}=\{0,1\}. Hence, the size of H\mathcal{H} is 22. It can be shown that it is the greatest possible answer.

In the second testcase we have n=3n=3. The optimal arrangement is:

The arrangement with cells located in (2,1)(2,1), (2,3)(2,3) and (3,1)(3,1).

H\mathcal{H}={22+11,22+33,33+11,22+13,23+11,23+31}\{|2-2|+|1-1|,|2-2|+|3-3|,|3-3|+|1-1|,|2-2|+|1-3|,|2-3|+|1-1|,|2-3|+|3-1|\}={0,0,0,2,1,3}\{0,0,0,2,1,3\}={0,1,2,3}\{0,1,2,3\}.

For n=4n=4 a possible arrangement is:

For n=5n=5 a possible arrangement is:

For n=6n=6 a possible arrangement is: