#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 /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main(void) {
  int s, i, j, k, num;
  char t[9];
  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    scanf("%d", &s);
    printf("Case %d:\n", i + 1);
    for (j = 0; j < 10; j++) {
      s = s * s;
      sprintf(t, "%08d", s);
      s = (t[5] - '0') + (t[4] - '0') * 10 + (t[3] - '0') * 100 +
          (t[2] - '0') * 1000;
      printf("%d\n", s);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1213 <main+0xe3>
lea    0xe97(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    1200 <main+0xd0>
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0x21(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe60(%rip),%rsi
call   1050 <sprintf@plt>
movsbl -0x1c(%rbp),%eax
sub    $0x30,%eax
movsbl -0x1d(%rbp),%ecx
sub    $0x30,%ecx
imul   $0xa,%ecx,%ecx
add    %ecx,%eax
movsbl -0x1e(%rbp),%ecx
sub    $0x30,%ecx
imul   $0x64,%ecx,%ecx
add    %ecx,%eax
movsbl -0x1f(%rbp),%ecx
sub    $0x30,%ecx
imul   $0x3e8,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118b <main+0x5b>
jmp    1205 <main+0xd5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1156 <main+0x26>
xor    %eax,%eax
add    $0x30,%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    0xebb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1210 <main+0xe0>
xor    %r13d,%r13d
lea    0xe9f(%rip),%r12
lea    0xea2(%rip),%rbx
lea    0xf(%rsp),%rbp
lea    0xe9b(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    0xe79(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
add    $0x1,%r13d
mov    %r12,%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
mov    $0xa,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    0x4(%rsp),%edx
imul   %edx,%edx
mov    %edx,0x4(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <sprintf@plt>
movsbl 0x14(%rsp),%eax
movsbl 0x13(%rsp),%ecx
lea    (%rcx,%rcx,4),%ecx
movsbl 0x12(%rsp),%edx
imul   $0x64,%edx,%edx
movsbl 0x11(%rsp),%esi
imul   $0x3e8,%esi,%esi
lea    (%rax,%rcx,2),%eax
add    %edx,%eax
add    %eax,%esi
add    $0xffff2fb0,%esi
mov    %esi,0x4(%rsp)
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%r15d
jne    11b0 <main+0x80>
cmp    0x8(%rsp),%r13d
jl     1180 <main+0x50>
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 = [10 x i8] c"Case %d:\0A\00"
@.str.2 = [5 x i8] c"%08d\00"
@.str.3 = [4 x i8] c"%d\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 [9 x i8]
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %3
br label %9
9: ; preds = %56, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %59
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 0, i32* %4
br label %18
18: ; preds = %52, %13
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %55
21: ; preds = %18
%22 = load i32, i32* %2
%23 = load i32, i32* %2
%24 = mul nsw i32 %22, %23
store i32 %24, i32* %2
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* %2
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 48
%32 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 4
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 48
%36 = mul nsw i32 %35, 10
%37 = add nsw i32 %31, %36
%38 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 3
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 48
%42 = mul nsw i32 %41, 100
%43 = add nsw i32 %37, %42
%44 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 2
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = sub nsw i32 %46, 48
%48 = mul nsw i32 %47, 1000
%49 = add nsw i32 %43, %48
store i32 %49, i32* %2
%50 = load i32, i32* %2
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %21
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %18
55: ; preds = %18
br label %56
56: ; preds = %55
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %9
59: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"Case %d:\0A\00"
@.str.2 = [5 x i8] c"%08d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [9 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %46
10: ; preds = %0
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 5
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 4
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 3
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 2
br label %18
15: ; preds = %23
%16 = load i32, i32* %2
%17 = icmp slt i32 %21, %16
br i1 %17, label %18, label %46
18: ; preds = %10, %15
%19 = phi i32 [ 0, %10 ], [ %21, %15 ]
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%21 = add nuw nsw i32 %19, 1
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %18, %23
%24 = phi i32 [ 0, %18 ], [ %44, %23 ]
%25 = load i32, i32* %1
%26 = mul nsw i32 %25, %25
store i32 %26, i32* %1
%27 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i8, i8* %11
%29 = sext i8 %28 to i32
%30 = load i8, i8* %12
%31 = sext i8 %30 to i32
%32 = mul nsw i32 %31, 10
%33 = load i8, i8* %13
%34 = sext i8 %33 to i32
%35 = mul nsw i32 %34, 100
%36 = load i8, i8* %14
%37 = sext i8 %36 to i32
%38 = mul nsw i32 %37, 1000
%39 = add nsw i32 %29, -53328
%40 = add nsw i32 %39, %32
%41 = add nsw i32 %40, %35
%42 = add nsw i32 %41, %38
store i32 %42, i32* %1
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i32 %24, 1
%45 = icmp eq i32 %44, 10
br i1 %45, label %15, label %23
46: ; preds = %15, %0
ret i32 0
}