#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);
int scanf(char *, ...);
int main() {
  long long n, a, s, c;
  int t, i;
  while (scanf("%d", &t) == 1) {
    for (i = 1; i <= t; i++) {
      scanf("%lld", &n);
      a = n;
      c = 0;
      while (1) {
        s = 0;
        while (n != 0) {
          s = s * 10 + n % 10;
          n /= 10;
        }
        if (s == a)
          break;
        else {
          n = s + a;
          a = s + a;
          c++;
        }
      }
      printf("%lld %lld\n", c, a);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    122e <main+0x10e>
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     1229 <main+0x109>
lea    0xe9f(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11cb <main+0xab>
imul   $0xa,-0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    -0x38(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    1187 <main+0x67>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11de <main+0xbe>
jmp    1207 <main+0xe7>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117f <main+0x5f>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1151 <main+0x31>
jmp    112f <main+0xf>
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    0xecb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1233 <main+0x113>
lea    0xeb2(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xeab(%rip),%r15
movabs $0x6666666666666667,%rbp
66 66 66
jmp    118c <main+0x6c>
nopl   0x0(%rax)
lea    0xe89(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1233 <main+0x113>
cmpl   $0x0,0xc(%rsp)
jle    1170 <main+0x50>
mov    $0x1,%r14d
jmp    11b9 <main+0x99>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r8,%rdx
call   1030 <printf@plt>
lea    0x1(%r14),%eax
cmp    0xc(%rsp),%r14d
mov    %eax,%r14d
jge    1170 <main+0x50>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%r8
xor    %esi,%esi
nopl   (%rax)
xor    %eax,%eax
test   %r8,%r8
je     121c <main+0xfc>
mov    %r8,%rdx
nopw   0x0(%rax,%rax,1)
mov    %rdx,%rcx
lea    (%rax,%rax,4),%rbx
mov    %rdx,%rax
imul   %rbp
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%rax
lea    (%rax,%rax,4),%rax
mov    %rcx,%rdi
sub    %rax,%rdi
lea    (%rdi,%rbx,2),%rax
add    $0x9,%rcx
cmp    $0x12,%rcx
ja     11e0 <main+0xc0>
mov    %rdx,0x10(%rsp)
cmp    %r8,%rax
je     11a0 <main+0x80>
add    %rax,%r8
mov    %r8,0x10(%rsp)
add    $0x1,%rsi
jmp    11d0 <main+0xb0>
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 i32
%7 = alloca i32
store i32 0, i32* %1
br label %8
8: ; preds = %53, %0
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %54
11: ; preds = %8
store i32 1, i32* %7
br label %12
12: ; preds = %50, %11
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %12
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%18 = load i64, i64* %2
store i64 %18, i64* %3
store i64 0, i64* %5
br label %19
19: ; preds = %16, %45
store i64 0, i64* %4
br label %20
20: ; preds = %23, %19
%21 = load i64, i64* %2
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i64, i64* %4
%25 = mul nsw i64 %24, 10
%26 = load i64, i64* %2
%27 = srem i64 %26, 10
%28 = add nsw i64 %25, %27
store i64 %28, i64* %4
%29 = load i64, i64* %2
%30 = sdiv i64 %29, 10
store i64 %30, i64* %2
br label %20
31: ; preds = %20
%32 = load i64, i64* %4
%33 = load i64, i64* %3
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
br label %46
36: ; preds = %31
%37 = load i64, i64* %4
%38 = load i64, i64* %3
%39 = add nsw i64 %37, %38
store i64 %39, i64* %2
%40 = load i64, i64* %4
%41 = load i64, i64* %3
%42 = add nsw i64 %40, %41
store i64 %42, i64* %3
%43 = load i64, i64* %5
%44 = add nsw i64 %43, 1
store i64 %44, i64* %5
br label %45
45: ; preds = %36
br label %19
46: ; preds = %35
%47 = load i64, i64* %5
%48 = load i64, i64* %3
%49 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %47, i64 %48)
br label %50
50: ; preds = %46
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %12
53: ; preds = %12
br label %8
54: ; preds = %8
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 i32
%3 = bitcast i64* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %10, label %42
7: ; preds = %37, %10
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %42
10: ; preds = %0, %7
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 1
br i1 %12, label %7, label %13
13: ; preds = %10, %37
%14 = phi i32 [ %39, %37 ], [ 1, %10 ]
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%16 = load i64, i64* %1
br label %17
17: ; preds = %34, %13
%18 = phi i64 [ %16, %13 ], [ %35, %34 ]
%19 = phi i64 [ 0, %13 ], [ %36, %34 ]
%20 = icmp eq i64 %18, 0
br i1 %20, label %31, label %21
21: ; preds = %17, %21
%22 = phi i64 [ %26, %21 ], [ 0, %17 ]
%23 = phi i64 [ %27, %21 ], [ %18, %17 ]
%24 = mul nsw i64 %22, 10
%25 = srem i64 %23, 10
%26 = add nsw i64 %24, %25
%27 = sdiv i64 %23, 10
%28 = add i64 %23, 9
%29 = icmp ult i64 %28, 19
br i1 %29, label %30, label %21
30: ; preds = %21
store i64 %27, i64* %1
br label %31
31: ; preds = %30, %17
%32 = phi i64 [ %26, %30 ], [ 0, %17 ]
%33 = icmp eq i64 %32, %18
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = add nsw i64 %32, %18
store i64 %35, i64* %1
%36 = add nuw nsw i64 %19, 1
br label %17
37: ; preds = %31
%38 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %19, i64 %18)
%39 = add nuw nsw i32 %14, 1
%40 = load i32, i32* %2
%41 = icmp slt i32 %14, %40
br i1 %41, label %13, label %7
42: ; preds = %7, %0
ret i32 0
}