__author__ = 'Himanshi'

'''Question URL: https://www.hackerrank.com/challenges/sherlock-and-the-beast'''


t = int(raw_input())
i = 0
while i < t:
    n = int(raw_input())
    c = 5*(2*n%3)
    if c > n:
        print(-1)
    else:
        print('5' * (n-c) + '3'*c)
    i += 1
e6f858f7c20d1c1b0987afa84ed8d5778560d878
<mask token>

<mask token>
while i < t:
    n = int(raw_input())
    c = 5 * (2 * n % 3)
    if c > n:
        print(-1)
    else:
        print('5' * (n - c) + '3' * c)
    i += 1

__author__ = 'Himanshi'
<mask token>
t = int(raw_input())
i = 0
while i < t:
    n = int(raw_input())
    c = 5 * (2 * n % 3)
    if c > n:
        print(-1)
    else:
        print('5' * (n - c) + '3' * c)
    i += 1

__author__ = 'Himanshi'

'''Question URL: https://www.hackerrank.com/challenges/sherlock-and-the-beast'''


t = int(raw_input())
i = 0
while i < t:
    n = int(raw_input())
    c = 5*(2*n%3)
    if c > n:
        print(-1)
    else:
        print('5' * (n-c) + '3'*c)
    i += 1