#include<bits/stdc++.h>
using namespace std;
int b[12]={-1,1,7,4,2,6,8,10,18,22,20,28};
int c[7]={6,8,10,18,20,20,28};
int main()
{
int n;
cin>>n;
while(n--)
{
int x;
cin>>x;
if(x<=12)cout<<b[x-1]<<endl;
else
{
x-=12;
int jj=x/7;
int yy=x%7;
if(x%7!=0)jj++;
cout<<c[yy-1];
if(yy-1==4)
{
cout<<0;
jj--;
}
for(int i=1;i<=jj;i++)cout<<8;
cout<<endl;
}
}
return 0;
}