#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int t;
  scanf("%d", &t);
  for (int a0 = 0; a0 < t; a0++) {
    int n;
    int x;
    scanf("%d", &n);
    x = n;
    while ((x % 3) != 0) {
      x = x - 5;
    }
    if (x < 0) {
      printf("-1\n");
    } else {
      for (int i = 0; i < x; i++) {
        printf("5");
      }
      for (int i = 0; i < (n - x); i++) {
        printf("3");
      }
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1223 <main+0x103>
lea    0xea7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     118a <main+0x6a>
mov    -0x14(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x14(%rbp)
jmp    1168 <main+0x48>
cmpl   $0x0,-0x14(%rbp)
jge    11a5 <main+0x85>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
jmp    1210 <main+0xf0>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d2 <main+0xb2>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <main+0x8c>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    1204 <main+0xe4>
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d9 <main+0xb9>
lea    0xdfa(%rip),%rdi
call   1030 <printf@plt>
jmp    1215 <main+0xf5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    121d <main+0xed>
xor    %r13d,%r13d
lea    0xe9f(%rip),%r14
mov    %rsp,%r12
lea    0xe98(%rip),%r15
jmp    1189 <main+0x59>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13d
cmp    0x4(%rsp),%r13d
jge    121d <main+0xed>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%eax
lea    0x5(%rax),%ebx
mov    %eax,%ecx
nopl   0x0(%rax)
mov    %ecx,%ebp
add    $0xfffffffb,%ebx
imul   $0xaaaaaaab,%ebx,%edx
add    $0x2aaaaaaa,%edx
lea    -0x5(%rbp),%ecx
cmp    $0x55555554,%edx
ja     11a0 <main+0x70>
test   %ebx,%ebx
js     1210 <main+0xe0>
je     11e2 <main+0xb2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x35,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0xa0>
mov    (%rsp),%eax
cmp    %ebx,%eax
jle    1170 <main+0x40>
neg    %ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x33,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    (%rsp),%eax
add    %ebx,%eax
cmp    %eax,%ebp
jl     11f0 <main+0xc0>
jmp    1170 <main+0x40>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <puts@plt>
jmp    117a <main+0x4a>
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"-1\0A\00"
@.str.2 = [2 x i8] c"5\00"
@.str.3 = [2 x i8] c"3\00"
@.str.4 = [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
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %9
9: ; preds = %53, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %56
13: ; preds = %9
%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
store i32 %15, i32* %5
br label %16
16: ; preds = %20, %13
%17 = load i32, i32* %5
%18 = srem i32 %17, 3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 5
store i32 %22, i32* %5
br label %16
23: ; preds = %16
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %52
28: ; preds = %23
store i32 0, i32* %6
br label %29
29: ; preds = %35, %28
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %29
38: ; preds = %29
store i32 0, i32* %7
br label %39
39: ; preds = %47, %38
%40 = load i32, i32* %7
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = sub nsw i32 %41, %42
%44 = icmp slt i32 %40, %43
br i1 %44, label %45, label %50
45: ; preds = %39
%46 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %39
50: ; preds = %39
%51 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %26
br label %53
53: ; preds = %52
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %9
56: ; preds = %9
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 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = bitcast i32* %2 to i8*
br label %10
9: ; preds = %44, %0
ret i32 0
10: ; preds = %7, %44
%11 = phi i32 [ 0, %7 ], [ %45, %44 ]
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
br label %14
14: ; preds = %14, %10
%15 = phi i32 [ %13, %10 ], [ %18, %14 ]
%16 = srem i32 %15, 3
%17 = icmp eq i32 %16, 0
%18 = add nsw i32 %15, -5
br i1 %17, label %19, label %14
19: ; preds = %14
%20 = icmp slt i32 %15, 0
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = icmp eq i32 %15, 0
br i1 %22, label %27, label %30
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %44
25: ; preds = %30
%26 = load i32, i32* %2
br label %27
27: ; preds = %25, %21
%28 = phi i32 [ %26, %25 ], [ %13, %21 ]
%29 = icmp sgt i32 %28, %15
br i1 %29, label %37, label %35
30: ; preds = %21, %30
%31 = phi i32 [ %33, %30 ], [ 0, %21 ]
%32 = call i32 @putchar(i32 53)
%33 = add nuw nsw i32 %31, 1
%34 = icmp eq i32 %33, %15
br i1 %34, label %25, label %30
35: ; preds = %37, %27
%36 = call i32 @putchar(i32 10)
br label %44
37: ; preds = %27, %37
%38 = phi i32 [ %40, %37 ], [ 0, %27 ]
%39 = call i32 @putchar(i32 51)
%40 = add nuw nsw i32 %38, 1
%41 = load i32, i32* %2
%42 = sub nsw i32 %41, %15
%43 = icmp slt i32 %40, %42
br i1 %43, label %37, label %35
44: ; preds = %35, %23
%45 = add nuw nsw i32 %11, 1
%46 = load i32, i32* %1
%47 = icmp slt i32 %45, %46
br i1 %47, label %10, label %9
}