#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 case_num;
  scanf("%d", &case_num);
  while (case_num--) {
    int amplitude, frequency;
    int index, temp;
    scanf("%d%d", &amplitude, &frequency);
    while (frequency--) {
      for (index = 1; index <= amplitude; index++) {
        temp = index;
        while (temp--)
          printf("%d", index);
        printf("\n");
      }
      for (index = amplitude - 1; index >= 1; index--) {
        temp = index;
        while (temp--)
          printf("%d", index);
        printf("\n");
      }
      if (frequency)
        printf("\n");
    }
    if (case_num)
      printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1277 <main+0x157>
lea    0xea4(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     125a <main+0x13a>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11de <main+0xbe>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     11c2 <main+0xa2>
mov    -0x14(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1198 <main+0x78>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <main+0x66>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     123d <main+0x11d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1221 <main+0x101>
mov    -0x14(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f7 <main+0xd7>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <main+0xc7>
cmpl   $0x0,-0x10(%rbp)
je     1255 <main+0x135>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116b <main+0x4b>
cmpl   $0x0,-0x8(%rbp)
je     1272 <main+0x152>
lea    0xd9a(%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    0xebd(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0x10(%rsp)
jae    1169 <main+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc(%rsp),%r12
lea    0xe8d(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe79(%rip),%rdi
lea    0x14(%rsp),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0xc(%rsp)
jb     1273 <main+0x143>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,0x14(%rsp)
jle    1257 <main+0x127>
mov    $0x1,%ebx
mov    $0xffffffff,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
inc    %ebp
jne    11e0 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%eax
mov    0x14(%rsp),%r15d
add    $0xffffffff,%r14d
cmp    %r15d,%ebx
mov    %eax,%ebx
jl     11d0 <main+0xa0>
cmp    $0x2,%r15d
jl     1257 <main+0x127>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x1(%r15),%ebx
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1230 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x2,%r15d
mov    %ebx,%r15d
jg     1220 <main+0xf0>
cmpl   $0x0,0xc(%rsp)
je     12a0 <main+0x170>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0xc(%rsp)
jae    11b0 <main+0x80>
cmpl   $0x0,0x10(%rsp)
je     1158 <main+0x28>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0x10(%rsp)
jae    1180 <main+0x50>
jmp    1158 <main+0x28>
nopl   0x0(%rax,%rax,1)
movl   $0xffffffff,0xc(%rsp)
ff
cmpl   $0x0,0x10(%rsp)
jne    127e <main+0x14e>
jmp    1158 <main+0x28>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 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
store i32 0, i32* %1
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %68, %0
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %69
12: ; preds = %8
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
br label %14
14: ; preds = %62, %12
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %63
18: ; preds = %14
store i32 1, i32* %5
br label %19
19: ; preds = %34, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = load i32, i32* %5
store i32 %24, i32* %6
br label %25
25: ; preds = %29, %23
%26 = load i32, i32* %6
%27 = add nsw i32 %26, -1
store i32 %27, i32* %6
%28 = icmp ne i32 %26, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %25
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %19
37: ; preds = %19
%38 = load i32, i32* %3
%39 = sub nsw i32 %38, 1
store i32 %39, i32* %5
br label %40
40: ; preds = %54, %37
%41 = load i32, i32* %5
%42 = icmp sge i32 %41, 1
br i1 %42, label %43, label %57
43: ; preds = %40
%44 = load i32, i32* %5
store i32 %44, i32* %6
br label %45
45: ; preds = %49, %43
%46 = load i32, i32* %6
%47 = add nsw i32 %46, -1
store i32 %47, i32* %6
%48 = icmp ne i32 %46, 0
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i32, i32* %5
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %50)
br label %45
52: ; preds = %45
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52
%55 = load i32, i32* %5
%56 = add nsw i32 %55, -1
store i32 %56, i32* %5
br label %40
57: ; preds = %40
%58 = load i32, i32* %4
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %60, %57
br label %14
63: ; preds = %14
%64 = load i32, i32* %2
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
br label %8
69: ; preds = %8
ret i32 0
}

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