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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1201 <main+0xd1>
lea    0xe96(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11af <main+0x7f>
mov    -0x10(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119c <main+0x6c>
jmp    11af <main+0x7f>
jmp    11a1 <main+0x71>
mov    -0x10(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <main+0x49>
cmpl   $0x0,-0x10(%rbp)
jl     11e9 <main+0xb9>
mov    -0x10(%rbp),%esi
mov    $0x35,%edi
call   1030 <p@plt>
mov    -0xc(%rbp),%esi
sub    -0x10(%rbp),%esi
mov    $0x33,%edi
call   1030 <p@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fc <main+0xcc>
lea    0xe13(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    114f <main+0x1f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
subl   $0x1,0x4(%rsp)
jb     1203 <main+0xc3>
lea    0xe96(%rip),%r14
mov    %rsp,%rbx
lea    0xe8f(%rip),%r15
jmp    1196 <main+0x56>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1050 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1203 <main+0xc3>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%ebp
add    $0x5,%ebp
nopw   0x0(%rax,%rax,1)
add    $0xfffffffb,%ebp
js     11d3 <main+0x93>
movslq %ebp,%rax
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
jne    11b0 <main+0x70>
test   %ebp,%ebp
js     1180 <main+0x40>
mov    $0x35,%edi
mov    %ebp,%esi
call   1040 <p@plt>
mov    (%rsp),%esi
sub    %ebp,%esi
mov    $0x33,%edi
call   1040 <p@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0x4(%rsp)
jae    1196 <main+0x56>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c"%d\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* %2)
br label %6
6: ; preds = %38, %0
%7 = load i32, i32* %2
%8 = add nsw i32 %7, -1
store i32 %8, i32* %2
%9 = icmp ne i32 %7, 0
br i1 %9, label %10, label %39
10: ; preds = %6
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
store i32 %12, i32* %4
br label %13
13: ; preds = %22, %10
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32, i32* %4
%18 = srem i32 %17, 3
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %25
21: ; preds = %16
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 5
store i32 %24, i32* %4
br label %13
25: ; preds = %20, %13
%26 = load i32, i32* %4
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i32, i32* %4
%30 = call i32 @p(i8 signext 53, i32 %29)
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = sub nsw i32 %31, %32
%34 = call i32 @p(i8 signext 51, i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %38
36: ; preds = %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 -1)
br label %38
38: ; preds = %36, %28
br label %6
39: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.2 = [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 nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %32, label %9
9: ; preds = %0, %28
%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
br label %12
12: ; preds = %12, %9
%13 = phi i32 [ %11, %9 ], [ %18, %12 ]
%14 = icmp sgt i32 %13, -1
%15 = srem i32 %13, 3
%16 = icmp ne i32 %15, 0
%17 = and i1 %14, %16
%18 = add nsw i32 %13, -5
br i1 %17, label %12, label %19
19: ; preds = %12
br i1 %14, label %20, label %26
20: ; preds = %19
%21 = call i32 @p(i8 signext 53, i32 %13)
%22 = load i32, i32* %2
%23 = sub nsw i32 %22, %13
%24 = call i32 @p(i8 signext 51, i32 %23)
%25 = call i32 @putchar(i32 10)
br label %28
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 -1)
br label %28
28: ; preds = %26, %20
%29 = load i32, i32* %1
%30 = add nsw i32 %29, -1
store i32 %30, i32* %1
%31 = icmp eq i32 %29, 0
br i1 %31, label %32, label %9
32: ; preds = %28, %0
ret i32 0
}