#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,t;
char s1[N],s2[N];
char f1[N],f2[N];
bool checka(){
	char tmp=s1[1];
	for(int i=1;i<=n;i++) if(tmp!=s1[i]) return false;
	return true;
}
bool checkb(){
	for(int i=1;i<=n;i++) if(f1[i]!=f2[i]) return false;
	return true;
}

int main()
{
    freopen("edit.in","r",stdin);
    freopen("edit.out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++) cin>>s1[i];
		for(int i=1;i<=n;i++) cin>>s2[i];
		for(int i=1;i<=n;i++) cin>>f1[i];
		for(int i=1;i<=n;i++) cin>>f2[i];
		if(checka()){//A
			char tmp=s1[1];
			int ans=0;
			for(int i=1;i<=n;i++) if(s2[i]==tmp) ans++;
			cout<<ans<<endl;
			continue;
		}
		else cout<<(int)sqrt(n)<<endl;
	}
	
	return 0;
}

