#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 dig(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int m, N, T;
  scanf("%d", &T);
  for (; T > 0; T--) {
    scanf("%d", &N);
    m = N % 3;
    if (m == 2 && (N - 5) > -1) {
      printf("%lld\n", dig(N - 5) * 100000 + 33333);
    } else if (m == 0) {
      printf("%lld\n", dig(N));
    } else if (m == 1 && (N - 10) > -1) {
      printf("%lld\n", dig(N - 10) * 1000000000 + 3333333333);
    } else
      printf("-1\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jle    1259 <main+0x129>
lea    0xea0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11ba <main+0x8a>
mov    -0xc(%rbp),%eax
sub    $0x5,%eax
cmp    $0xffffffff,%eax
jle    11ba <main+0x8a>
mov    -0xc(%rbp),%edi
sub    $0x5,%edi
call   1050 <dig@plt>
imul   $0x186a0,%eax,%esi
add    $0x8235,%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1246 <main+0x116>
cmpl   $0x0,-0x8(%rbp)
jne    11e1 <main+0xb1>
mov    -0xc(%rbp),%edi
call   1050 <dig@plt>
mov    %eax,%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <main+0x111>
cmpl   $0x1,-0x8(%rbp)
jne    122e <main+0xfe>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
cmp    $0xffffffff,%eax
jle    122e <main+0xfe>
mov    -0xc(%rbp),%edi
sub    $0xa,%edi
call   1050 <dig@plt>
imul   $0x3b9aca00,%eax,%eax
movslq %eax,%rsi
movabs $0xc6aea155,%rax
add    %rax,%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <main+0x10c>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <main+0x111>
jmp    1246 <main+0x116>
jmp    124b <main+0x11b>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    114f <main+0x1f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeac(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    124b <main+0x10b>
lea    0xe90(%rip),%r14
lea    0xc(%rsp),%rbx
lea    0xe87(%rip),%r15
mov    $0xc6aea155,%r13d
lea    0xe80(%rip),%r12
jmp    11ac <main+0x6c>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
cmp    $0x1,%eax
jle    124b <main+0x10b>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movslq 0xc(%rsp),%rdi
imul   $0x55555556,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%ecx
mov    %edi,%eax
sub    %ecx,%eax
cmp    $0x5,%rdi
jl     1200 <main+0xc0>
cmp    $0x2,%eax
jne    1200 <main+0xc0>
add    $0xfffffffb,%edi
call   1060 <dig@plt>
imul   $0x186a0,%eax,%esi
add    $0x8235,%esi
mov    %r15,%rdi
jmp    1213 <main+0xd3>
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%eax
je     121f <main+0xdf>
test   %eax,%eax
jne    1190 <main+0x50>
call   1060 <dig@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1198 <main+0x58>
cmp    $0xa,%edi
jl     1190 <main+0x50>
add    $0xfffffff6,%edi
call   1060 <dig@plt>
imul   $0x3b9aca00,%eax,%eax
movslq %eax,%rsi
add    %r13,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1198 <main+0x58>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
@.str.2 = [4 x i8] c"-1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
br label %6
6: ; preds = %53, %0
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %56
9: ; preds = %6
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = srem i32 %11, 3
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %26
15: ; preds = %9
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 5
%18 = icmp sgt i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 5
%22 = call i32 @dig(i32 %21)
%23 = mul nsw i32 %22, 100000
%24 = add nsw i32 %23, 33333
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %52
26: ; preds = %15, %9
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %3
%31 = call i32 @dig(i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %51
33: ; preds = %26
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = load i32, i32* %3
%38 = sub nsw i32 %37, 10
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = load i32, i32* %3
%42 = sub nsw i32 %41, 10
%43 = call i32 @dig(i32 %42)
%44 = mul nsw i32 %43, 1000000000
%45 = sext i32 %44 to i64
%46 = add nsw i64 %45, 3333333333
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %46)
br label %50
48: ; preds = %36, %33
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %40
br label %51
51: ; preds = %50, %29
br label %52
52: ; preds = %51, %19
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, -1
store i32 %55, i32* %4
br label %6
56: ; preds = %6
ret i32 0
}

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