代码如下
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
int num=1;
while(t--) {
int len;
scanf("%d",&len);
map<string,bool> m;
string s1,s2,s12;
cin>>s1>>s2>>s12;
printf("%d ",num++);
int cnt=0;
int flag=-1;
while(true) {
cnt++;
string temp;
int tt=0;
while(tt<len) {
temp+=s2[tt];
temp+=s1[tt];
tt++;
}
if(temp==s12) {
flag=1;
break;
}
if(m[temp]==true) {
flag=0; break;
}
m[temp]=true;
s1=temp.substr(0,len);
s2=temp.substr(len);
}
if(flag==1) {
printf("%d\n",cnt);
}
else{
printf("-1\n");
}
}
}