include[HTML_REMOVED]
using namespace std;
int a[10];
int l[20],xx1[20],xx2[20];
int n,t;
int ans;
vector[HTML_REMOVED] v[100];
void dfs(int x)
{
if(x==9)
{
ans;
for(int i=1;i<=8;i) v[ans].push_back(a[i]);
return;
}
for(int i=1;i<=8;i)
{
if(l[i]==0&&xx1[i-x+8]==0&&xx2[i+x]==0)
{
a[x]=i;
l[i]=1;
xx1[i-x+8]=1;
xx2[i+x]=1;
dfs(x+1);
l[i]=0;
xx1[i-x+8]=0;
xx2[i+x]=0;
}
}
}
int main()
{
ans=0;
dfs(1);
cin>>t;
while(t–)
{
cin>>n;
for(int i=0;i<8;i) cout<<v[n][i];
cout<<endl;
}
return 0;
}