#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 */
typedef int /*<<< orphan*/ ans;

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, const char *argv[]) {
  int ans[100005];
  int t, n;
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i < 100005; i++) {
    int x = i, y = i;
    while (x > 0) {
      y += x % 10;
      x = x / 10;
    }
    if (ans[y] == 0)
      ans[y] = i;
  }
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    printf("%d\n", ans[n]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61ad0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x61ab0(%rbp),%rdi
xor    %esi,%esi
mov    $0x61a94,%edx
call   1040 <memset@plt>
movl   $0x1,-0x61abc(%rbp)
cmpl   $0x186a5,-0x61abc(%rbp)
jge    1210 <main+0xe0>
mov    -0x61abc(%rbp),%eax
mov    %eax,-0x61ac0(%rbp)
mov    -0x61abc(%rbp),%eax
mov    %eax,-0x61ac4(%rbp)
cmpl   $0x0,-0x61ac0(%rbp)
jle    11ce <main+0x9e>
mov    -0x61ac0(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x61ac4(%rbp),%edx
mov    %edx,-0x61ac4(%rbp)
mov    -0x61ac0(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x61ac0(%rbp)
jmp    118e <main+0x5e>
movslq -0x61ac4(%rbp),%rax
cmpl   $0x0,-0x61ab0(%rbp,%rax,4)
jne    11f7 <main+0xc7>
mov    -0x61abc(%rbp),%ecx
movslq -0x61ac4(%rbp),%rax
mov    %ecx,-0x61ab0(%rbp,%rax,4)
jmp    11fc <main+0xcc>
mov    -0x61abc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61abc(%rbp)
jmp    1166 <main+0x36>
lea    0xde9(%rip),%rdi
lea    -0x61ab4(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x61ab4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x61ab4(%rbp)
cmp    $0x0,%eax
je     126f <main+0x13f>
lea    0xdbc(%rip),%rdi
lea    -0x61ab8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x61ab8(%rbp),%rax
mov    -0x61ab0(%rbp,%rax,4),%esi
lea    0xd9e(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <main+0xf3>
xor    %eax,%eax
add    $0x61ad0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x61ab0,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x61a94,%edx
call   1040 <memset@plt>
mov    $0x1,%r8d
mov    $0xcccccccd,%ecx
jmp    116d <main+0x3d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r8d
cmp    $0x186a5,%r8d
je     11ad <main+0x7d>
mov    %r8d,%edx
mov    %r8d,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
imul   %rcx,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %eax,%esi
sub    %ebx,%esi
add    %esi,%edx
cmp    $0x9,%eax
mov    %edi,%eax
ja     1180 <main+0x50>
mov    %edx,%edx
cmpl   $0x0,0x10(%rsp,%rdx,4)
jne    1160 <main+0x30>
mov    %r8d,0x10(%rsp,%rdx,4)
jmp    1160 <main+0x30>
lea    0xe4c(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x8(%rsp)
jb     1203 <main+0xd3>
lea    0xe34(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xe2b(%rip),%rbx
nopl   0x0(%rax,%rax,1)
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    $0x61ab0,%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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100005 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = getelementptr inbounds [100005 x i32], [100005 x i32]* %6, i64 0, i64 0
%13 = call i32 @memset(i32* %12, i32 0, i32 400020)
store i32 1, i32* %9
br label %14
14: ; preds = %42, %2
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 100005
br i1 %16, label %17, label %45
17: ; preds = %14
%18 = load i32, i32* %9
store i32 %18, i32* %10
%19 = load i32, i32* %9
store i32 %19, i32* %11
br label %20
20: ; preds = %23, %17
%21 = load i32, i32* %10
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* %10
%25 = srem i32 %24, 10
%26 = load i32, i32* %11
%27 = add nsw i32 %26, %25
store i32 %27, i32* %11
%28 = load i32, i32* %10
%29 = sdiv i32 %28, 10
store i32 %29, i32* %10
br label %20
30: ; preds = %20
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100005 x i32], [100005 x i32]* %6, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i32, i32* %9
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100005 x i32], [100005 x i32]* %6, i64 0, i64 %39
store i32 %37, i32* %40
br label %41
41: ; preds = %36, %30
br label %42
42: ; preds = %41
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %14
45: ; preds = %14
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
br label %47
47: ; preds = %51, %45
%48 = load i32, i32* %7
%49 = add nsw i32 %48, -1
store i32 %49, i32* %7
%50 = icmp ne i32 %48, 0
br i1 %50, label %51, label %58
51: ; preds = %47
%52 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [100005 x i32], [100005 x i32]* %6, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %56)
br label %47
58: ; preds = %47
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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100005 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [100005 x i32]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds [100005 x i32], [100005 x i32]* %3, i64 0, i64 0
%10 = call i32 @memset(i32* %9, i32 0, i32 400020)
br label %11
11: ; preds = %2, %31
%12 = phi i32 [ 1, %2 ], [ %32, %31 ]
br label %18
13: ; preds = %31
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp eq i32 %15, 0
br i1 %17, label %44, label %34
18: ; preds = %11, %18
%19 = phi i32 [ %12, %11 ], [ %22, %18 ]
%20 = phi i32 [ %12, %11 ], [ %23, %18 ]
%21 = urem i32 %20, 10
%22 = add nuw nsw i32 %19, %21
%23 = udiv i32 %20, 10
%24 = icmp ult i32 %20, 10
br i1 %24, label %25, label %18
25: ; preds = %18
%26 = zext i32 %22 to i64
%27 = getelementptr inbounds [100005 x i32], [100005 x i32]* %3, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 %12, i32* %27
br label %31
31: ; preds = %30, %25
%32 = add nuw nsw i32 %12, 1
%33 = icmp eq i32 %32, 100005
br i1 %33, label %13, label %11
34: ; preds = %13, %34
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100005 x i32], [100005 x i32]* %3, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %4
%42 = add nsw i32 %41, -1
store i32 %42, i32* %4
%43 = icmp eq i32 %41, 0
br i1 %43, label %44, label %34
44: ; preds = %34, %13
ret i32 0
}