#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 /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int i, j, k, l, n, t, h;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &h);
    for (k = 1; k <= h; k++) {
      for (j = 1; j <= n; j++) {
        for (i = 1; i <= j; i++) {
          printf("%d", j);
        }
        printf("\n");
      }
      for (j = n - 1; j >= 1; j--) {
        for (i = j; i >= 1; i--) {
          printf("%d", j);
        }
        printf("\n");
      }
      if (k != h) {
        printf("\n");
      }
    }
    if (t != 0) {
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1287 <main+0x167>
lea    0xea4(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     126a <main+0x14a>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11df <main+0xbf>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11c3 <main+0xa3>
mov    -0xc(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1198 <main+0x78>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1185 <main+0x65>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     123d <main+0x11d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1221 <main+0x101>
mov    -0xc(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11f8 <main+0xd8>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11e8 <main+0xc8>
mov    -0x10(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1257 <main+0x137>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125c <main+0x13c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <main+0x52>
cmpl   $0x0,-0x1c(%rbp)
je     1282 <main+0x162>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1141 <main+0x21>
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
sub    $0x18,%rsp
lea    0xebe(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0x10(%rsp)
jb     128c <main+0x15c>
lea    0xea0(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe89(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1270 <main+0x140>
mov    $0x1,%r12d
jmp    11b1 <main+0x81>
nopl   0x0(%rax,%rax,1)
lea    0x1(%r12),%ecx
cmp    %eax,%r12d
mov    %ecx,%r12d
jge    1270 <main+0x140>
cmpl   $0x0,0x14(%rsp)
jle    1249 <main+0x119>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%eax
mov    0x14(%rsp),%r14d
cmp    %r14d,%ebx
mov    %eax,%ebx
jl     11d0 <main+0xa0>
cmp    $0x2,%r14d
jl     1249 <main+0x119>
lea    -0x1(%r14),%ebx
mov    %r14d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1220 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x2,%r14d
mov    %ebx,%r14d
jg     1210 <main+0xe0>
mov    %r12d,%eax
cmp    0xc(%rsp),%r12d
je     11a0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%eax
jmp    11a0 <main+0x70>
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,0x10(%rsp)
je     128c <main+0x15c>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0x10(%rsp)
jae    1170 <main+0x40>
xor    %eax,%eax
add    $0x18,%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 = [6 x i8] c"%d %d\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
br label %10
10: ; preds = %78, %0
%11 = load i32, i32* %7
%12 = add nsw i32 %11, -1
store i32 %12, i32* %7
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %79
14: ; preds = %10
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32* %8)
store i32 1, i32* %4
br label %16
16: ; preds = %70, %14
%17 = load i32, i32* %4
%18 = load i32, i32* %8
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %73
20: ; preds = %16
store i32 1, i32* %3
br label %21
21: ; preds = %38, %20
%22 = load i32, i32* %3
%23 = load i32, i32* %6
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %21
store i32 1, i32* %2
br label %26
26: ; preds = %33, %25
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %26
36: ; preds = %26
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %21
41: ; preds = %21
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %3
br label %44
44: ; preds = %60, %41
%45 = load i32, i32* %3
%46 = icmp sge i32 %45, 1
br i1 %46, label %47, label %63
47: ; preds = %44
%48 = load i32, i32* %3
store i32 %48, i32* %2
br label %49
49: ; preds = %55, %47
%50 = load i32, i32* %2
%51 = icmp sge i32 %50, 1
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i32, i32* %3
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %52
%56 = load i32, i32* %2
%57 = add nsw i32 %56, -1
store i32 %57, i32* %2
br label %49
58: ; preds = %49
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58
%61 = load i32, i32* %3
%62 = add nsw i32 %61, -1
store i32 %62, i32* %3
br label %44
63: ; preds = %44
%64 = load i32, i32* %4
%65 = load i32, i32* %8
%66 = icmp ne i32 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %69
69: ; preds = %67, %63
br label %70
70: ; preds = %69
%71 = load i32, i32* %4
%72 = add nsw i32 %71, 1
store i32 %72, i32* %4
br label %16
73: ; preds = %16
%74 = load i32, i32* %7
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %78
78: ; preds = %76, %73
br label %10
79: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = add nsw i32 %8, -1
store i32 %9, i32* %2
%10 = icmp eq i32 %8, 0
br i1 %10, label %64, label %11
11: ; preds = %0, %59
%12 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %3)
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 1
br i1 %14, label %56, label %15
15: ; preds = %11, %52
%16 = phi i32 [ %54, %52 ], [ 1, %11 ]
%17 = load i32, i32* %1
%18 = icmp slt i32 %17, 1
br i1 %18, label %46, label %21
19: ; preds = %29
%20 = icmp sgt i32 %32, 1
br i1 %20, label %35, label %46
21: ; preds = %15, %29
%22 = phi i32 [ %34, %29 ], [ 2, %15 ]
%23 = phi i32 [ %31, %29 ], [ 1, %15 ]
br label %24
24: ; preds = %21, %24
%25 = phi i32 [ 1, %21 ], [ %27, %24 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
%27 = add nuw i32 %25, 1
%28 = icmp eq i32 %27, %22
br i1 %28, label %29, label %24
29: ; preds = %24
%30 = call i32 @putchar(i32 10)
%31 = add nuw nsw i32 %23, 1
%32 = load i32, i32* %1
%33 = icmp slt i32 %23, %32
%34 = add nuw i32 %22, 1
br i1 %33, label %21, label %19
35: ; preds = %19, %43
%36 = phi i32 [ %37, %43 ], [ %32, %19 ]
%37 = add nsw i32 %36, -1
br label %38
38: ; preds = %35, %38
%39 = phi i32 [ %41, %38 ], [ %37, %35 ]
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %37)
%41 = add nsw i32 %39, -1
%42 = icmp ugt i32 %39, 1
br i1 %42, label %38, label %43
43: ; preds = %38
%44 = call i32 @putchar(i32 10)
%45 = icmp sgt i32 %36, 2
br i1 %45, label %35, label %46
46: ; preds = %43, %15, %19
%47 = load i32, i32* %3
%48 = icmp eq i32 %16, %47
br i1 %48, label %52, label %49
49: ; preds = %46
%50 = call i32 @putchar(i32 10)
%51 = load i32, i32* %3
br label %52
52: ; preds = %46, %49
%53 = phi i32 [ %16, %46 ], [ %51, %49 ]
%54 = add nuw nsw i32 %16, 1
%55 = icmp slt i32 %16, %53
br i1 %55, label %15, label %56
56: ; preds = %52, %11
%57 = load i32, i32* %2
%58 = icmp eq i32 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %56
%60 = call i32 @putchar(i32 10)
%61 = load i32, i32* %2
%62 = add nsw i32 %61, -1
store i32 %62, i32* %2
%63 = icmp eq i32 %61, 0
br i1 %63, label %64, label %11
64: ; preds = %59, %56, %0
ret i32 0
}