#include <bits/stdc++.h>
using namespace std;
const int LR=1e5+5;
char s1[LR],s2[LR],t1[LR],t2[LR];
bool vis1[LR],vis2[LR];
int pre1[LR],pre2[LR]; 
int planA(int n){
	int x=0;
	for(int i=0;i<n;++i) if(s2[i]==s1[0]) x++;
	return x;
}
int planB(int n){
	int x=0,num[2][2]={0,0,0,0};
	for(int i=0;i<n;++i){
		if(vis1[i]==false){
			if(s1[i]==s2[i]) x++;
			x+=min(num[0][0],num[1][0]);
			x+=min(num[0][1],num[1][1]);
			num[0][0]=0;num[1][0]=0;num[0][1]=0;num[1][1]=0;
		}
		else{
			num[0][s1[i]-'0']++;
			num[1][s2[i]-'0']++;
		}
	}
	x+=min(num[0][0],num[1][0]);
	x+=min(num[0][1],num[1][1]);
	return x;
}
void solve(int t){
	int n;
	cin>>n;
	scanf("%s%s%s%s",s1,s2,t1,t2);
	memset(vis1,0,sizeof(vis1));
	memset(vis2,0,sizeof(vis2));
	for(int i=0;i<n;++i){
		if(t1[i]=='1') vis1[i]=1;
		if(t2[i]=='1') vis2[i]=1;
	}
	bool A=true;
	for(int i=1;i<n;++i) if(s1[i-1]!=s1[i]) A=false;
	if(A) {cout<<planA(n)<<endl;return;}
	bool B=true;
	for(int i=0;i<n;++i) if(vis1[i]!=vis2[i]) B=false;
	if(B) {cout<<planB(n)<<endl;return;}
	cout<<n<<endl;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin>>t;
	for(int i=1;i<=t;++i) solve(i); 
}
