The ECHELON and Arrow

3.9

14 votes
Problem

Arrow is getting paranoid about Malcom merlyn, his arch-enemy. All his efforts to subdue Merlyn have been in vain. These days Arrow is working on a problem with John Diggle. Diggle mentioned that the Felicity has been facing weird problem with their supercomputer, 'The ECHELON', recently.

This afternoon, Arrow received a note from Merlyn, Saying that he has infected 'The ECHELON' with a virus. Moreover, the note had the number X printed on it. After doing some calculations, Arrow's friend Felicity figured out that the key to remove the virus is the largest Decent Number having X digits.

A Decent Number has the following properties:

  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.

Meanwhile, the counter to the destruction of 'The ECHELON' is running very fast. Can you save 'The ECHELON', and find the key before Arrow's friend Felicity?

Input Format

The 1st line will contain an integer T, the number of test cases. This is followed by T lines, each containing an integer X. i.e. the number of digits in the number.

Output Format

Largest Decent Number having X digits. If no such number exists, tell Arrow that he is wrong and print -1.

Constraints

1<= T <= 20 1<= X <= 100000

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

For N=1, there is no such number. For N=3, 555 is the only possible number. For N=5, 33333 is the only possible number. For N=11, 55555533333 and all permutations of these digits are valid numbers; among them, the given number is the largest one.

Editor Image

?