#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*/ assert(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int testcases;
  int nd;
  int n5;
  const int impossible = -1;
  scanf("%d", &testcases);
  assert(testcases >= 1 && testcases <= 20);
  for (int i = 0; i < testcases; i++) {
    scanf("%d", &nd);
    assert(nd >= 1 && nd <= 100000);
    if (nd <= 2)
      printf("%d\n", impossible);
    else if (nd % 3 == 0) {
      for (int i = 0; i < nd; i++)
        printf("%d", 5);
      printf("\n");
    } else {
      n5 = nd;
      while (n5 > 0) {
        n5 -= 5;
        if (n5 < 0) {
          printf("%d\n", impossible);
          break;
        } else {
          if (n5 % 3 == 0) {
            for (int i = 0; i < n5; i++)
              printf("%d", 5);
            for (int i = 0; i < nd - n5; i++)
              printf("%d", 3);
            printf("\n");
            break;
          }
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x25(%rbp)
jl     116f <main+0x3f>
cmpl   $0x14,-0x8(%rbp)
setle  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    133b <main+0x20b>
lea    0xe6a(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x1,-0xc(%rbp)
mov    %al,-0x26(%rbp)
jl     11bb <main+0x8b>
cmpl   $0x186a0,-0xc(%rbp)
setle  %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x2,-0xc(%rbp)
jg     11ea <main+0xba>
lea    0xe2a(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1328 <main+0x1f8>
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1245 <main+0x115>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1232 <main+0x102>
lea    0xde8(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1205 <main+0xd5>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1323 <main+0x1f3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    131e <main+0x1ee>
mov    -0x10(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1280 <main+0x150>
lea    0xd94(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131e <main+0x1ee>
mov    -0x10(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1314 <main+0x1e4>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12c8 <main+0x198>
lea    0xd52(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    129b <main+0x16b>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    1301 <main+0x1d1>
lea    0xd19(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12cf <main+0x19f>
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131e <main+0x1ee>
jmp    1319 <main+0x1e9>
jmp    124b <main+0x11b>
jmp    1323 <main+0x1f3>
jmp    1328 <main+0x1f8>
jmp    132d <main+0x1fd>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1183 <main+0x53>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
xor    %edi,%edi
cmp    $0x14,%eax
setb   %dil
call   1050 <assert@plt>
cmpl   $0x0,0x4(%rsp)
jle    12b6 <main+0x176>
lea    0xe7d(%rip),%r13
mov    %rsp,%rbp
mov    $0xaaaaaaab,%r12d
xor    %r14d,%r14d
jmp    11c2 <main+0x82>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe5c(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
jge    12b6 <main+0x176>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%eax
add    $0xffffffff,%eax
xor    %edi,%edi
cmp    $0x186a0,%eax
setb   %dil
call   1050 <assert@plt>
mov    (%rsp),%eax
cmp    $0x2,%eax
jle    11a0 <main+0x60>
imul   $0xaaaaaaab,%eax,%ecx
mov    %eax,%ebx
cmp    $0x55555556,%ecx
jb     128d <main+0x14d>
nop
mov    %ebx,%r15d
sub    $0x5,%ebx
jb     11a0 <main+0x60>
mov    %ebx,%ecx
imul   %r12,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%ecx
cmp    %ebx,%ecx
jne    1200 <main+0xc0>
lea    0x5(%rbx),%ecx
cmp    $0x6,%ecx
jb     124a <main+0x10a>
mov    $0x5,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1230 <main+0xf0>
mov    (%rsp),%eax
cmp    %ebx,%eax
jle    127b <main+0x13b>
neg    %ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    (%rsp),%eax
add    %ebx,%eax
cmp    %eax,%ebp
jl     1260 <main+0x120>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%rbp
jmp    11b3 <main+0x73>
xor    %ebx,%ebx
nop
mov    %r13,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     1290 <main+0x150>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11b3 <main+0x73>
xor    %eax,%eax
add    $0x8,%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 = [4 x i8] c"%d\0A\00"
@.str.2 = [2 x i8] c"\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 i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %5
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp sge i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* %2
%15 = icmp sle i32 %14, 20
br label %16
16: ; preds = %13, %0
%17 = phi i1 [ false, %0 ], [ %15, %13 ]
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
store i32 0, i32* %6
br label %20
20: ; preds = %100, %16
%21 = load i32, i32* %6
%22 = load i32, i32* %2
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %103
24: ; preds = %20
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = icmp sge i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %3
%30 = icmp sle i32 %29, 100000
br label %31
31: ; preds = %28, %24
%32 = phi i1 [ false, %24 ], [ %30, %28 ]
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %3
%36 = icmp sle i32 %35, 2
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %99
39: ; preds = %31
%40 = load i32, i32* %3
%41 = srem i32 %40, 3
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %55
43: ; preds = %39
store i32 0, i32* %7
br label %44
44: ; preds = %50, %43
%45 = load i32, i32* %7
%46 = load i32, i32* %3
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 5)
br label %50
50: ; preds = %48
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %44
53: ; preds = %44
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %98
55: ; preds = %39
%56 = load i32, i32* %3
store i32 %56, i32* %4
br label %57
57: ; preds = %96, %55
%58 = load i32, i32* %4
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %97
60: ; preds = %57
%61 = load i32, i32* %4
%62 = sub nsw i32 %61, 5
store i32 %62, i32* %4
%63 = load i32, i32* %4
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %97
67: ; preds = %60
%68 = load i32, i32* %4
%69 = srem i32 %68, 3
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %95
71: ; preds = %67
store i32 0, i32* %8
br label %72
72: ; preds = %78, %71
%73 = load i32, i32* %8
%74 = load i32, i32* %4
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %81
76: ; preds = %72
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 5)
br label %78
78: ; preds = %76
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
br label %72
81: ; preds = %72
store i32 0, i32* %9
br label %82
82: ; preds = %90, %81
%83 = load i32, i32* %9
%84 = load i32, i32* %3
%85 = load i32, i32* %4
%86 = sub nsw i32 %84, %85
%87 = icmp slt i32 %83, %86
br i1 %87, label %88, label %93
88: ; preds = %82
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
br label %90
90: ; preds = %88
%91 = load i32, i32* %9
%92 = add nsw i32 %91, 1
store i32 %92, i32* %9
br label %82
93: ; preds = %82
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %97
95: ; preds = %67
br label %96
96: ; preds = %95
br label %57
97: ; preds = %93, %65, %57
br label %98
98: ; preds = %97, %53
br label %99
99: ; preds = %98, %37
br label %100
100: ; preds = %99
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 1
store i32 %102, i32* %6
br label %20
103: ; preds = %20
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 = 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* %1)
%6 = load i32, i32* %1
%7 = add i32 %6, -1
%8 = icmp ult i32 %7, 20
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %67, %0
ret i32 0
14: ; preds = %0, %67
%15 = phi i32 [ %68, %67 ], [ 0, %0 ]
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = add i32 %17, -1
%19 = icmp ult i32 %18, 100000
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 3
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %67
26: ; preds = %14
%27 = urem i32 %22, 3
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %37
29: ; preds = %31
%30 = call i32 @putchar(i32 10)
br label %67
31: ; preds = %26, %31
%32 = phi i32 [ %34, %31 ], [ 0, %26 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 5)
%34 = add nuw nsw i32 %32, 1
%35 = load i32, i32* %2
%36 = icmp slt i32 %34, %35
br i1 %36, label %31, label %29
37: ; preds = %26, %43
%38 = phi i32 [ %39, %43 ], [ %22, %26 ]
%39 = add nsw i32 %38, -5
%40 = icmp ult i32 %38, 5
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %67
43: ; preds = %37
%44 = urem i32 %39, 3
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %37
46: ; preds = %43
%47 = icmp ugt i32 %38, 5
br i1 %47, label %53, label %50
48: ; preds = %53
%49 = load i32, i32* %2
br label %50
50: ; preds = %48, %46
%51 = phi i32 [ %49, %48 ], [ %22, %46 ]
%52 = icmp sgt i32 %51, %39
br i1 %52, label %60, label %58
53: ; preds = %46, %53
%54 = phi i32 [ %56, %53 ], [ 0, %46 ]
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 5)
%56 = add nuw nsw i32 %54, 1
%57 = icmp eq i32 %56, %39
br i1 %57, label %48, label %53
58: ; preds = %60, %50
%59 = call i32 @putchar(i32 10)
br label %67
60: ; preds = %50, %60
%61 = phi i32 [ %63, %60 ], [ 0, %50 ]
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%63 = add nuw nsw i32 %61, 1
%64 = load i32, i32* %2
%65 = sub nsw i32 %64, %39
%66 = icmp slt i32 %63, %65
br i1 %66, label %60, label %58
67: ; preds = %24, %41, %58, %29
%68 = add nuw nsw i32 %15, 1
%69 = load i32, i32* %1
%70 = icmp slt i32 %68, %69
br i1 %70, label %14, label %13
}