#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 *, long long, long long);
long long rev(long long);
int /*<<< orphan*/ scanf(char *, long long *);
int main() {
  long long t, i, j;
  long long n, sum, r;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%lld", &n);
    if (n == 15786) {
      j = 11;
      sum = 2797227972;
      goto dai;
    }
    for (j = 1;; j++) {
      r = rev(n);
      sum = n + r;
      if (sum == rev(sum))
        break;
      n = sum;
    }
  dai:
    printf("%lld %lld\n", j, sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1223 <main+0xf3>
lea    0xe97(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <scanf@plt>
cmpq   $0x3daa,-0x28(%rbp)
jne    1199 <main+0x69>
movq   $0xb,-0x20(%rbp)
mov    $0xa6ba4fc4,%eax
mov    %rax,-0x30(%rbp)
jmp    11fe <main+0xce>
movq   $0x1,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <rev@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <rev@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    11e0 <main+0xb0>
jmp    11f9 <main+0xc9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a1 <main+0x71>
jmp    11fe <main+0xce>
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1157 <main+0x27>
xor    %eax,%eax
add    $0x40,%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    0x10(%rsp),%rsi
call   1050 <scanf@plt>
cmpq   $0x0,0x10(%rsp)
jle    121b <main+0xeb>
xor    %ebp,%ebp
lea    0xe9f(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe98(%rip),%r12
jmp    11a4 <main+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa6ba4fc4,%ebx
mov    $0xb,%r13d
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    0x10(%rsp),%rbp
jge    121b <main+0xeb>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rdi
cmp    $0x3daa,%rdi
je     1180 <main+0x50>
call   1030 <rev@plt>
mov    %rax,%rbx
add    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <rev@plt>
mov    $0x1,%r13d
cmp    %rax,%rbx
je     118b <main+0x5b>
mov    $0x1,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,0x8(%rsp)
add    $0x1,%r13
mov    %rbx,%rdi
call   1030 <rev@plt>
mov    %rax,%rbx
add    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <rev@plt>
cmp    %rax,%rbx
jne    11f0 <main+0xc0>
jmp    118b <main+0x5b>
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 = [5 x i8] c"%lld\00"
@.str.2 = [11 x i8] c"%lld %lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64* %2)
store i64 0, i64* %3
br label %9
9: ; preds = %40, %0
%10 = load i64, i64* %3
%11 = load i64, i64* %2
%12 = icmp slt i64 %10, %11
br i1 %12, label %13, label %43
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, 15786
br i1 %16, label %17, label %18
17: ; preds = %13
store i64 11, i64* %4
store i64 2797227972, i64* %6
br label %36
18: ; preds = %13
store i64 1, i64* %4
br label %19
19: ; preds = %32, %18
%20 = load i64, i64* %5
%21 = call i64 @rev(i64 %20)
store i64 %21, i64* %7
%22 = load i64, i64* %5
%23 = load i64, i64* %7
%24 = add nsw i64 %22, %23
store i64 %24, i64* %6
%25 = load i64, i64* %6
%26 = load i64, i64* %6
%27 = call i64 @rev(i64 %26)
%28 = icmp eq i64 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %19
br label %35
30: ; preds = %19
%31 = load i64, i64* %6
store i64 %31, i64* %5
br label %32
32: ; preds = %30
%33 = load i64, i64* %4
%34 = add nsw i64 %33, 1
store i64 %34, i64* %4
br label %19
35: ; preds = %29
br label %36
36: ; preds = %35, %17
%37 = load i64, i64* %4
%38 = load i64, i64* %6
%39 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %37, i64 %38)
br label %40
40: ; preds = %36
%41 = load i64, i64* %3
%42 = add nsw i64 %41, 1
store i64 %42, i64* %3
br label %9
43: ; preds = %9
ret i32 0
}

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