#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*/ dig(int, 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)
      dig(N - 5, N);
    else if (m == 0 && N > 0)
      dig(N, 0);
    else if (m == 1 && (N - 10) > -1)
      dig(N - 10, N);
    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    121b <main+0xeb>
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    11a3 <main+0x73>
mov    -0xc(%rbp),%eax
sub    $0x5,%eax
cmp    $0xffffffff,%eax
jle    11a3 <main+0x73>
mov    -0xc(%rbp),%edi
sub    $0x5,%edi
mov    -0xc(%rbp),%esi
call   1050 <dig@plt>
jmp    1208 <main+0xd8>
cmpl   $0x0,-0x8(%rbp)
jne    11c6 <main+0x96>
cmpl   $0x0,-0xc(%rbp)
jle    11c6 <main+0x96>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1050 <dig@plt>
jmp    1203 <main+0xd3>
cmpl   $0x1,-0x8(%rbp)
jne    11f2 <main+0xc2>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
cmp    $0xffffffff,%eax
jle    11f2 <main+0xc2>
mov    -0xc(%rbp),%edi
sub    $0xa,%edi
mov    -0xc(%rbp),%esi
call   1050 <dig@plt>
jmp    11fe <main+0xce>
lea    0xe0a(%rip),%rdi
call   1030 <printf@plt>
jmp    1203 <main+0xd3>
jmp    1208 <main+0xd8>
jmp    120d <main+0xdd>
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   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11e9 <main+0xb9>
lea    0xea4(%rip),%r14
lea    0xc(%rsp),%rbx
lea    0xe9b(%rip),%r15
jmp    1188 <main+0x58>
nopw   0x0(%rax,%rax,1)
lea    -0x5(%rsi),%edi
call   1050 <dig@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
cmp    $0x1,%eax
jle    11e9 <main+0xb9>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
movslq 0xc(%rsp),%rsi
imul   $0x55555556,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%ecx
mov    %esi,%eax
sub    %ecx,%eax
cmp    $0x5,%rsi
jl     11be <main+0x8e>
cmp    $0x2,%eax
je     1170 <main+0x40>
test   %esi,%esi
jle    11d0 <main+0xa0>
test   %eax,%eax
jne    11d0 <main+0xa0>
mov    %esi,%edi
xor    %esi,%esi
jmp    1173 <main+0x43>
nopl   0x0(%rax)
cmp    $0xa,%esi
jl     11df <main+0xaf>
cmp    $0x1,%eax
jne    11df <main+0xaf>
lea    -0xa(%rsi),%edi
jmp    1173 <main+0x43>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    1178 <main+0x48>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [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 = %50, %0
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %53
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 %24
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 %24
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 5
%22 = load i32, i32* %3
%23 = call i32 @dig(i32 %21, i32 %22)
br label %49
24: ; preds = %15, %9
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %3
%32 = call i32 @dig(i32 %31, i32 0)
br label %48
33: ; preds = %27, %24
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %45
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 %45
40: ; preds = %36
%41 = load i32, i32* %3
%42 = sub nsw i32 %41, 10
%43 = load i32, i32* %3
%44 = call i32 @dig(i32 %42, i32 %43)
br label %47
45: ; preds = %36, %33
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %40
br label %48
48: ; preds = %47, %30
br label %49
49: ; preds = %48, %19
br label %50
50: ; preds = %49
%51 = load i32, i32* %4
%52 = add nsw i32 %51, -1
store i32 %52, i32* %4
br label %6
53: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\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 %37
8: ; preds = %0, %33
%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 %18
15: ; preds = %8
%16 = add nsw i32 %10, -5
%17 = call i32 @dig(i32 %16, i32 %10)
br label %33
18: ; preds = %8
%19 = icmp eq i32 %11, 0
%20 = icmp sgt i32 %10, 0
%21 = and i1 %20, %19
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @dig(i32 %10, i32 0)
br label %33
24: ; preds = %18
%25 = icmp eq i32 %11, 1
%26 = icmp sgt i32 %10, 9
%27 = and i1 %26, %25
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = add nsw i32 %10, -10
%30 = call i32 @dig(i32 %29, i32 %10)
br label %33
31: ; preds = %24
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %15, %28, %31, %22
%34 = load i32, i32* %2
%35 = add nsw i32 %34, -1
store i32 %35, i32* %2
%36 = icmp sgt i32 %34, 1
br i1 %36, label %8, label %37
37: ; preds = %33, %0
ret i32 0
}