#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 main() {
  int T, num, i, a, b, ans[100100] = {0};
  for (i = 1; i <= 100000; i++) {
    a = b = i;
    while (a) {
      b += a % 10;
      a /= 10;
    }
    if (!ans[b])
      ans[b] = i;
  }
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &num);
    printf("%d\n", ans[num]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61c30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x61c30(%rbp),%rdi
xor    %esi,%esi
mov    $0x61c10,%edx
call   1040 <memset@plt>
movl   $0x1,-0x10(%rbp)
cmpl   $0x186a0,-0x10(%rbp)
jg     11d3 <main+0xa3>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a0 <main+0x70>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x18(%rbp),%edx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    1172 <main+0x42>
movslq -0x18(%rbp),%rax
cmpl   $0x0,-0x61c30(%rbp,%rax,4)
jne    11c0 <main+0x90>
mov    -0x10(%rbp),%ecx
movslq -0x18(%rbp),%rax
mov    %ecx,-0x61c30(%rbp,%rax,4)
jmp    11c5 <main+0x95>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115c <main+0x2c>
lea    0xe26(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1223 <main+0xf3>
lea    0xe02(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0xc(%rbp),%rax
mov    -0x61c30(%rbp,%rax,4),%esi
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
jmp    11e3 <main+0xb3>
xor    %eax,%eax
add    $0x61c30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x61c20,%rsp
lea    0x10(%rsp),%rdi
mov    $0x61c10,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ecx
mov    %eax,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %edx,%rsi
imul   $0x66666667,%rsi,%rdx
mov    %rdx,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rdx
add    %edi,%edx
lea    (%rdx,%rdx,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %esi,%ebx
sub    %edi,%ebx
add    %ebx,%ecx
add    $0x9,%esi
cmp    $0x12,%esi
ja     1170 <main+0x40>
movslq %ecx,%rcx
mov    0x10(%rsp,%rcx,4),%edx
test   %edx,%edx
cmove  %eax,%edx
mov    %edx,0x10(%rsp,%rcx,4)
add    $0x1,%eax
cmp    $0x186a1,%eax
jne    1160 <main+0x30>
lea    0xe44(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x8(%rsp)
jb     1203 <main+0xd3>
lea    0xe2c(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xe23(%rip),%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movslq 0xc(%rsp),%rax
mov    0x10(%rsp,%rax,4),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
subl   $0x1,0x8(%rsp)
jae    11e0 <main+0xb0>
xor    %eax,%eax
add    $0x61c20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [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 [100100 x i32]
store i32 0, i32* %1
%8 = bitcast [100100 x i32]* %7 to i8*
store i32 1, i32* %4
br label %9
9: ; preds = %36, %0
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 100000
br i1 %11, label %12, label %39
12: ; preds = %9
%13 = load i32, i32* %4
store i32 %13, i32* %6
store i32 %13, i32* %5
br label %14
14: ; preds = %17, %12
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %5
%19 = srem i32 %18, 10
%20 = load i32, i32* %6
%21 = add nsw i32 %20, %19
store i32 %21, i32* %6
%22 = load i32, i32* %5
%23 = sdiv i32 %22, 10
store i32 %23, i32* %5
br label %14
24: ; preds = %14
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100100 x i32], [100100 x i32]* %7, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %24
%31 = load i32, i32* %4
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100100 x i32], [100100 x i32]* %7, i64 0, i64 %33
store i32 %31, i32* %34
br label %35
35: ; preds = %30, %24
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %9
39: ; preds = %9
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %41
41: ; preds = %45, %39
%42 = load i32, i32* %2
%43 = add nsw i32 %42, -1
store i32 %43, i32* %2
%44 = icmp ne i32 %42, 0
br i1 %44, label %45, label %52
45: ; preds = %41
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [100100 x i32], [100100 x i32]* %7, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %41
52: ; preds = %41
ret i32 0
}

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