#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 sherlockandthebeast(void) {
  int numCases;
  int numThrees[3];
  numThrees[0] = 0;
  numThrees[1] = 10;
  numThrees[2] = 5;
  scanf("%d", &numCases);
  while (numCases--) {
    int numDigits;
    scanf("%d", &numDigits);
    if (numDigits < 3 || numDigits == 4 || numDigits == 7) {
      printf("-1\n");
      continue;
    }
    int leftoverFives = numDigits % 3;
    for (int i = 0; i < numDigits - numThrees[leftoverFives]; i++) {
      printf("5");
    }
    for (int i = 0; i < numThrees[leftoverFives]; i++) {
      printf("3");
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<sherlockandthebeast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
movl   $0xa,-0xc(%rbp)
movl   $0x5,-0x8(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     1228 <sherlockandthebeast+0x108>
lea    0xe98(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x3,-0x14(%rbp)
jl     118f <sherlockandthebeast+0x6f>
cmpl   $0x4,-0x14(%rbp)
je     118f <sherlockandthebeast+0x6f>
cmpl   $0x7,-0x14(%rbp)
jne    11a0 <sherlockandthebeast+0x80>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
jmp    114d <sherlockandthebeast+0x2d>
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
movslq -0x18(%rbp),%rdx
sub    -0x10(%rbp,%rdx,4),%ecx
cmp    %ecx,%eax
jge    11e5 <sherlockandthebeast+0xc5>
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <sherlockandthebeast+0x95>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
movslq -0x18(%rbp),%rcx
cmp    -0x10(%rbp,%rcx,4),%eax
jge    1217 <sherlockandthebeast+0xf7>
lea    0xe05(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ec <sherlockandthebeast+0xcc>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
jmp    114d <sherlockandthebeast+0x2d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sherlockandthebeast>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0xa00000000,%rax
mov    %rax,0xc(%rsp)
movl   $0x5,0x14(%rsp)
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    117e <sherlockandthebeast+0x4e>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7b(%rip),%r14
lea    0x4(%rsp),%r13
lea    0xe72(%rip),%r15
mov    $0xaaaaaaab,%r12d
jmp    11af <sherlockandthebeast+0x7f>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <puts@plt>
subl   $0x1,0x8(%rsp)
jb     116d <sherlockandthebeast+0x3d>
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x3,%eax
jl     11a0 <sherlockandthebeast+0x70>
cmp    $0x7,%eax
je     11a0 <sherlockandthebeast+0x70>
cmp    $0x4,%eax
je     11a0 <sherlockandthebeast+0x70>
mov    %eax,%ecx
imul   %r12,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    0xc(%rsp,%rdx,4),%ebp
cmp    %ebp,%eax
jle    1207 <sherlockandthebeast+0xd7>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x35,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
mov    0x4(%rsp),%eax
sub    %ebp,%eax
cmp    %eax,%ebx
jl     11f0 <sherlockandthebeast+0xc0>
test   %ebp,%ebp
jle    121f <sherlockandthebeast+0xef>
nopl   0x0(%rax,%rax,1)
mov    $0x33,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1210 <sherlockandthebeast+0xe0>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0x8(%rsp)
jae    11af <sherlockandthebeast+0x7f>
jmp    116d <sherlockandthebeast+0x3d>

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 @sherlockandthebeast() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
store i32 0, i32* %7
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
store i32 10, i32* %8
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
store i32 5, i32* %9
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
br label %11
11: ; preds = %57, %25, %0
%12 = load i32, i32* %1
%13 = add nsw i32 %12, -1
store i32 %13, i32* %1
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %59
15: ; preds = %11
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 3
br i1 %18, label %25, label %19
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 4
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 7
br i1 %24, label %25, label %27
25: ; preds = %22, %19, %15
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %11
27: ; preds = %22
%28 = load i32, i32* %3
%29 = srem i32 %28, 3
store i32 %29, i32* %4
store i32 0, i32* %5
br label %30
30: ; preds = %41, %27
%31 = load i32, i32* %5
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = sub nsw i32 %32, %36
%38 = icmp slt i32 %31, %37
br i1 %38, label %39, label %44
39: ; preds = %30
%40 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %30
44: ; preds = %30
store i32 0, i32* %6
br label %45
45: ; preds = %54, %44
%46 = load i32, i32* %6
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = icmp slt i32 %46, %50
br i1 %51, label %52, label %57
52: ; preds = %45
%53 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %45
57: ; preds = %45
%58 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %11
59: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [3 x i8] c"-1\00"
define i32 @sherlockandthebeast() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast [3 x i32]* %2 to i8*
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
store i32 0, i32* %6
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
store i32 10, i32* %7
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
store i32 5, i32* %8
%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 = add nsw i32 %10, -1
store i32 %11, i32* %1
%12 = icmp eq i32 %10, 0
br i1 %12, label %49, label %13
13: ; preds = %0
%14 = bitcast i32* %3 to i8*
br label %15
15: ; preds = %13, %45
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %3
%18 = freeze i32 %17
%19 = icmp slt i32 %18, 3
br i1 %19, label %21, label %20
20: ; preds = %15
switch i32 %18, label %23 [
i32 7, label %21
i32 4, label %21
]
21: ; preds = %20, %20, %15
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %45
23: ; preds = %20
%24 = urem i32 %18, 3
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %18, %27
br i1 %28, label %31, label %29
29: ; preds = %31, %23
%30 = icmp sgt i32 %27, 0
br i1 %30, label %40, label %38
31: ; preds = %23, %31
%32 = phi i32 [ %34, %31 ], [ 0, %23 ]
%33 = call i32 @putchar(i32 53)
%34 = add nuw nsw i32 %32, 1
%35 = load i32, i32* %3
%36 = sub nsw i32 %35, %27
%37 = icmp slt i32 %34, %36
br i1 %37, label %31, label %29
38: ; preds = %40, %29
%39 = call i32 @putchar(i32 10)
br label %45
40: ; preds = %29, %40
%41 = phi i32 [ %43, %40 ], [ 0, %29 ]
%42 = call i32 @putchar(i32 51)
%43 = add nuw nsw i32 %41, 1
%44 = icmp eq i32 %43, %27
br i1 %44, label %38, label %40
45: ; preds = %38, %21
%46 = load i32, i32* %1
%47 = add nsw i32 %46, -1
store i32 %47, i32* %1
%48 = icmp eq i32 %46, 0
br i1 %48, label %49, label %15
49: ; preds = %45, %0
ret i32 0
}