the-treasure-lock
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

In vardhaman college of engineering, there is competition with name treasure lock.
To make this competition the key for the lock should satisfy following rules.
1 .3, 5, or both as its digits. No other digit is allowed.
2. Number of times 3 appears is divisible by 5.
3. Number of times 5 appears is divisible by 3.

Rakesh is very eager to win the championship. He is developing a code for that key.Assume yourself in that situation and solve for the key.

INPUT:
first line contains T testcases.
Next T lines consists of the number.
OUTPUT:
Output the number satisfying the above conditions.
if n cannot satisfy the above conditions print -1.

0<t<10
0<n<1000

SAMPLE INPUT
4
1
3
5
17

SAMPLE OUTPUT
-1
555
33333
55555555555533333


for _ in range(int(input())):
	c=0
	n=int(input())
	temp=n
	if n<3:
		print((-1), end=' ')
	elif n%15==0 or n%3==0:
		sum=0
		for j in range(n):
			sum=sum*10+5
		print((sum), end=' ')
	elif n%5==0:
		sum=0
		for j in range(n):
			sum=sum*10+3
		print((sum), end=' ')
	
	else:
		
		while n>5:
			n-=5
			sum=0
			if n%3==0 and (temp-n)%5==0:
				for o in range(n):
					sum=sum*10+5
				for o in range(temp-n):
					sum=sum*10+3
				print(sum, end=' ')
				break
		else:
			print((-1), end=' ')
	print();
		
		
			
					

		


def ans(n):
 
	if(n == 0):
	   return True
	elif(n < 0):
	   return False
	else:
		return ans(n-5) or ans(n-3)
	

for _ in range(eval(input())):
	n=eval(input())
	
	if ans(n):
		if(n%5==0):
			print(str(3)*n)
		else:
			c = 5*(2*n%3)
			print(str(5)*(n-c)+str(3)*c)
	else:
		print(-1)


for i in range(eval(input())):
	n=eval(input())
	if n%5==0:
		print("3"*n)
	elif n%3==0:
		print("5"*n)
	elif (n-5)%3==0:
		print("5"*(n-5)+"3"*5)
	elif (n-3)%5==0:
		print("3"*(n-3)+"5"*3)
	else:
		print("-1")


import sys
t=int(input())
while t>0:
	n=int(input())
	if n>=0 and n<=2:
		print(-1)
		t-=1
		continue
	else:
		if(n%3==0):
			z=n
			i=0
			while i<z:
				sys.stdout.write('5')
				i+=1
		elif (n%5==0):
			q=n
			j=0
			while j<q:
				sys.stdout.write('3')
				j+=1
		else:
			a=n-5
			b=5
			if a%3==0:
				i=0
				j=0
				while i<a:
					sys.stdout.write('5')
					i+=1
				while j<b:
					sys.stdout.write('3')
					j+=1
			else:
				print(-1)
	t-=1
	print() 
	
				


m3,m5=[0],[0]
for i in range(400):
	m3.append(i*3)
	m5.append(i*5)

def ans(n):
 
	if(n == 0):
	   return True
	elif(n < 0):
	   return False
	else:
		return ans(n-5) or ans(n-3)
	

for _ in range(eval(input())):
	x=eval(input())
	
	if(ans(x)):
		for i in m3:
			if(i<=x):
				for j in m5:
					if(i+j==x):
						n=i
						m=j
						break
			else:
				break
		if(x%5):
			print(str(5)*n+str(3)*m)
		else:
			print(str(3)*x)
	else:
		print(-1)


ta = int(input())
for _ in range(ta):
	n = int(input())
	if(n%3==0):
		cnt="5"
		while(n!=1):
			cnt+= "5"
			n-=1
		print(cnt)
		continue
	elif(n%5==0):
		cnt="3"
		while(n!=1):
			cnt += "3"
			n-=1
		print(cnt)
		continue
	elif(n==1 or n==2 or n==4):
		print(-1)
		continue
	temp = 0
	while(n!=5):
		n-=3
		temp+=3
	cnt="5"
	while(temp!=1):
		cnt +="5"
		
		temp-=1
	while(n!=0):
		cnt+="3"
		n-=1
	print(cnt)
	


def f(n):
	a=1
	b=0
	c=1
	x=[]
	while True:
		#print a,b
		if 5*a+3*b==n:
			x=[c,a,b]
			return x
			break
		else:
			b+=1
			if (5*a+3*b)>n:
				break
	a,b,c=0,1,2
	x=[]
	while True:
		#print a,b
		if 5*a+3*b==n:
			x=[c,a,b]
			return x
			break
		else:
			a+=1
			if (5*a+3*b)>n:
				break	
	return -1
for _ in range(eval(input())):
	n=eval(input())
	if n<3:
		print("-1")
		continue
	if n==3 or n%3==0:
		print("5"*n)
		continue
	if n==5 or n%5==0:
		print("3"*n)
		continue
	x=[]
	x=f(n)
	#print x
	if x!=-1:
		if x[0]==1:
			print("5"*(3*x[2])+"3"*(5*x[1]))
		else:
			print("5"*(3*x[1])+"3"*(5*x[2]))


def sol(n):
	ans=''
	if(n%5==0):
		ans='3'*n
		return ans
	c = 5*(2*n%3)
	if c > n:
		ans=str('-1')
	else:
		ans= str('5' * (n-c) + '3'*c)
	return ans


for x in range(0,eval(input())):
	n=eval(input())
	print(sol(n).strip())