//
// Created by xingchaoyue on 2019/7/27.
//
#include<iostream>
#include<cstdio>
#include<map>
#include<string.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull base = 131;
map<ull,ll>mp;
ull a[10010];
char s[10010];
int n,ans = 1;
int prime = 1e9+7;
ull mod = 2123704401301379571l;
ull hashe(char s[]){
int len = strlen(s);
ull ans = 0;
for(int i =0;i<len;++i){
ans = (ans*base+(ull)s[i])%mod+prime;
}
return ans;
}
char s1[1000],s2[1000],s3[1000];
char tmp[1000];
void gettmp(char *tmp,char *s1,char*s2){
int ps=0;
for(int i=0;i<n;i++)
{
tmp[ps++]=s2[i];
tmp[ps++]=s1[i];
}
tmp[ps]='\0';
}
int main(){
int t;
cin>>t;
int cnt = 1;
while(t--){
mp.clear();
cin>>n;
scanf("%s%s%s",s1,s2,s3);
int step = 0;
while(true){
gettmp(tmp,s1,s2);
step++;
if(!strcmp(tmp,s3)){
cout<<cnt++<<" "<<step<<endl;
break;
}
else if(mp[hashe(tmp)]&&strcmp(tmp,s3)){
cout<<cnt++<<" "<<-1<<endl;
break;
}
mp[hashe(tmp)] = 1;
memcpy(s1,tmp,n);
memcpy(s2,tmp+n,n);
}
}
}