#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int N = 0;
  int i, j;
  int test = 0;
  scanf("%d", &test);
  while (test != 0) {
    scanf("%d", &N);
    i = 0, j = N;
    while (i <= j) {
      if (i == j) {
        printf("%d %d\n", i, N - i);
        i++;
        j--;
      } else {
        printf("%d %d\n", i, N - i);
        i++;
        printf("%d %d\n", j, N - j);
        j--;
      }
    }
    --test;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1207 <main+0xe7>
lea    0xea2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11f9 <main+0xd9>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11b8 <main+0x98>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
sub    -0xc(%rbp),%edx
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11f4 <main+0xd4>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
sub    -0xc(%rbp),%edx
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
sub    -0x10(%rbp),%edx
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <main+0x54>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <main+0x2d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xebf(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
je     11d5 <main+0xb5>
lea    0xea6(%rip),%r12
jmp    1167 <main+0x47>
nop
addl   $0xffffffff,0x4(%rsp)
je     11d5 <main+0xb5>
lea    0xe92(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%r13d
test   %r13d,%r13d
js     1160 <main+0x40>
mov    %r13d,%r14d
neg    %r14d
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    11b8 <main+0x98>
nopl   0x0(%rax)
add    %r14d,%edx
add    %ebx,%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
lea    0x1(%rbx),%eax
lea    (%r15,%r13,1),%ecx
add    $0xffffffff,%ecx
mov    %r15d,%edx
add    $0xffffffff,%edx
mov    %edx,%r15d
cmp    %ecx,%ebx
mov    %eax,%ebx
jge    1160 <main+0x40>
lea    (%r15,%r13,1),%ebp
mov    (%rsp),%edx
cmp    %ebp,%ebx
je     1190 <main+0x70>
add    %r15d,%edx
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    (%rsp),%edx
jmp    1190 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %5
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
br label %7
7: ; preds = %47, %0
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %50
10: ; preds = %7
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
%12 = load i32, i32* %2
store i32 %12, i32* %4
br label %13
13: ; preds = %46, %10
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %47
17: ; preds = %13
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = sub nsw i32 %23, %24
%26 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %25)
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
br label %46
31: ; preds = %17
%32 = load i32, i32* %3
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = sub nsw i32 %33, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %35)
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
%39 = load i32, i32* %4
%40 = load i32, i32* %2
%41 = load i32, i32* %4
%42 = sub nsw i32 %40, %41
%43 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %42)
%44 = load i32, i32* %4
%45 = add nsw i32 %44, -1
store i32 %45, i32* %4
br label %46
46: ; preds = %31, %21
br label %13
47: ; preds = %13
%48 = load i32, i32* %5
%49 = add nsw i32 %48, -1
store i32 %49, i32* %5
br label %7
50: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %32, label %8
8: ; preds = %0, %28
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %8, %21
%13 = phi i32 [ %25, %21 ], [ %10, %8 ]
%14 = phi i32 [ %26, %21 ], [ 0, %8 ]
%15 = icmp eq i32 %14, %13
%16 = load i32, i32* %1
br i1 %15, label %21, label %17
17: ; preds = %12
%18 = sub nsw i32 %16, %14
%19 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %18)
%20 = load i32, i32* %1
br label %21
21: ; preds = %12, %17
%22 = phi i32 [ %20, %17 ], [ %16, %12 ]
%23 = sub nsw i32 %22, %13
%24 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %23)
%25 = add nsw i32 %13, -1
%26 = add nuw nsw i32 %14, 1
%27 = icmp slt i32 %14, %25
br i1 %27, label %12, label %28
28: ; preds = %21, %8
%29 = load i32, i32* %2
%30 = add nsw i32 %29, -1
store i32 %30, i32* %2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %8
32: ; preds = %28, %0
ret i32 0
}