#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
int n,c;
string s1,s2,aim;
void dfs(string x,string y,int step)
{
if((s1.compare(x)==0||s2.compare(y)==0)&&step>0)
{
printf("-1\n");
return;
}
string s12;
s12.clear();
for(int i=0;i<c;i++)
{
s12+=y[i];
s12+=x[i];
}//cout<<s12<<endl;
if(aim.compare(s12)==0)
{
printf("%d\n",step+1);
return;
}
else
{
x.clear();
y.clear();
for(int i=0;i<c;i++)
x+=s12[i];
for(int i=c;i<2*c;i++)
y+=s12[i];
dfs(x,y,step+1);
}
}
int main()
{
scanf("%d",&n);
int cnt=0;
while(n--)
{
cnt++;
scanf("%d",&c);
cin>>s1;
cin>>s2;
cin>>aim;
printf("%d ",cnt);
dfs(s1,s2,0);
}
return 0;
}