Detective and Santa
Difficulty: Hard

Its Chritmas ! You and your friend are waiting for Santa. But he hasnt come yet. You are getting paranoid of his archenemy. One of your friend mentioned that the everyone in the town has been facing weird problems with their computer, whom thet call 'The Monster', recently.On Chritmas afternoon, you received a note from one of his archenemy, saying that he has infected everyones computer 'The Monster' with a virus and if we solve them he will release our Santa. Moreover, the note had the number *P* printed on it. After doing some calculations, you figured out that the 'password' to remove the virus is the largest 'Best' Number having *P* digits. 

A 'Best' Number has -

3 or 5 or both in the number. No other digit is allowed.  
Number of times 3 appears mod 5 is 0.  
Number of times 5 appears mod  3 is 0.  
Meanwhile, the counter to destruction of 'The Monster' is running very fast. Can you save 'The Monster' and our Santa, and find the 'password' before me?

Input Format:
The 1st line  contain an integer T, the number of test cases.Followed by T lines, each having an integer P which is number of digits.

Output Format:
Largest Best number having P digits of password. If no such number exists, then print '-1' 

Constraints   
1<=T<=20   
1<=P<=100000  

Sample Input:
3  
1  
8  
15

Sample Output:
-1    
55533333     
555555555555555
   


Python 3 starter code:


Reference solution (C++):
<pre>
<p>#include &ltbits/stdc++.h></p>
using namespace std;                                                                                                                              
int main()                                                                             
{  
	int n,test,k,kstart;                                                                     
    cin>>test;                                                                                       
    while(test--)         
    {    
        cin>>n;             
    	string ks;
        for(int j=n ; j&gt;=0 ; i--)  
         {  
    		if(j%3==0 && (n-j)%5==0) 
     		{ 
     			ks=""; 
                for(int k=0 ; k&lt;j ; k++) 
    				ks+='5';<br>
    			for(int k=0 ; k&lt;n-j ; k++)
    				ks+='3';
                break;
            } 
        }  
        if(ks == "")  
            cout&lt;&lt;"-1"&lt;&lt;endl;  
        else  
            cout&lt;&lt;ks&lt;&lt;endl;  
    }  
    return 0;
}  
</pre>