#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int t,k;
char tmp[10];
char st1[10][10],st2[10][10];
vector<string> ans;
vector<char> st[10];
void prepare()
{
for(int j=0; j<5; j++)
{
for(int i=0; i<6; i++)
for(int k=0; k<6; k++)
if(st1[i][j]==st2[k][j])
{
st[j].push_back(st1[i][j]);
break;
}
}
}
void solve(int dep)
{
if(dep==5)
{
string st="";
for(int i=0; i<5; i++)
st+=tmp[i];
ans.push_back(st);
return ;
}
for(int i=0; i<st[dep].size(); i++)
{
tmp[dep]=st[dep][i];
solve(dep+1);
}
}
void init()
{
ans.clear();
for(int i=0; i<5; i++) st[i].clear();
}
int main()
{
scanf("%d",&t);
while(t--)
{
init();
cin>>k;
for(int i=0; i<6; i++)
scanf("%s",st1[i]);
for(int i=0; i<6; i++)
scanf("%s",st2[i]);
prepare();
solve(0);
sort(ans.begin(),ans.end());
int num=unique(ans.begin(),ans.end())-ans.begin();
if(num<k) printf("NO\n");
else cout<<ans[k-1]<<endl;
}
return 0;
}
UVA 1262(p323p)----Password
最新推荐文章于 2023-12-04 08:53:01 发布