#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, unsigned long);
unsigned long reverse(unsigned long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int nCases;
  unsigned long num;
  unsigned long rev;
  int count;
  scanf("%d\n", &nCases);
  while (nCases-- > 0) {
    scanf("%lu\n", &num);
    count = 0;
    while (num != (rev = reverse(num))) {
      num += rev;
      count++;
    }
    printf("%d %lu\n", count, num);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    11d5 <main+0xa5>
lea    0xe9b(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <reverse@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,-0x18(%rbp)
cmp    %rcx,%rax
je     11bd <main+0x8d>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117e <main+0x4e>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
jmp    1151 <main+0x21>
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    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    11ef <main+0xbf>
lea    0xe9c(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xe8d(%rip),%r12
jmp    119e <main+0x6e>
nopl   0x0(%rax)
mov    0x10(%rsp),%rdx
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    11ef <main+0xbf>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x10(%rsp),%r13
mov    %r13,%rdi
call   1030 <reverse@plt>
cmp    %rax,%r13
je     1180 <main+0x50>
mov    %rax,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    0x10(%rsp),%rbx
mov    %rbx,0x10(%rsp)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <reverse@plt>
cmp    %rax,%rbx
mov    %rax,%rbx
jne    11d0 <main+0xa0>
jmp    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 = [4 x i8] c"%d\0A\00"
@.str.1 = [5 x i8] c"%lu\0A\00"
@.str.2 = [8 x i8] c"%d %lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %24, %0
%8 = load i32, i32* %2
%9 = add nsw i32 %8, -1
store i32 %9, i32* %2
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %3)
store i32 0, i32* %5
br label %13
13: ; preds = %18, %11
%14 = load i64, i64* %3
%15 = load i64, i64* %3
%16 = call i64 @reverse(i64 %15)
store i64 %16, i64* %4
%17 = icmp ne i64 %14, %16
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i64, i64* %4
%20 = load i64, i64* %3
%21 = add i64 %20, %19
store i64 %21, i64* %3
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %13
24: ; preds = %13
%25 = load i32, i32* %5
%26 = load i64, i64* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %25, i64 %26)
br label %7
28: ; preds = %7
ret i32 0
}

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