#include"iostream" #include"string" #include"map" using namespace std; map<string,bool> mp; int main() { int t; cin>>t; int test=0; while(++test<=t) { int step=0; mp.clear(); int l; cin>>l; string s1; string s2; string s3; string s12=""; cin>>s1; cin>>s2; cin>>s3; while(true) { for(int i=0;i<l;i++) { s12+=s2[i]; s12+=s1[i]; } step++; if(s12.compare(s3)==0) { cout<<test<<" "<<step<<endl; break; } else if(mp[s12]==true) { cout<<test<<" "<<-1<<endl; break; } mp[s12]=true; int i; s1.clear(); s2.clear(); for(i=0;i<l;i++) { s1+=s12[i]; } for(;i<2*l;i++) { s2+=s12[i]; } s12.clear(); } } return 0; }