#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn=1e5+7;
struct node{
	int st,ed,num0,num1,id;
	bool empty(){return ((num0==0&&num1==0)||st>ed);}	
	void init(){num0=num1=0;return;}
};
char s1[maxn],s2[maxn],t1[maxn],t2[maxn];
int pre1[maxn],pre2[maxn];
node num1[maxn],num2[maxn];
int cnt1,cnt2;
void get_ans(int tot1,int tot0,node &fir,int &ans){
	int addd1=min(tot1,fir.num1),addd0=min(tot0,fir.num0);
	ans+=addd1+addd0;
	fir.num1-=tot1,fir.num0-=tot0;
	fir.num1=max(0,fir.num1);
	fir.num0=max(0,fir.num0);
	fir.st=fir.st+tot1+tot0;
	int ret=fir.ed-fir.st+1;
	fir.num0=min(fir.num0,ret);
	fir.num1=min(fir.num1,ret);
	return;
}
void solve(node &fir,node &sec,int &ans){
	int l=fir.st,r=min(sec.st-1,fir.ed);
	int id=fir.id;
	int tot1,tot0;
	if(id==1){
		tot1=pre2[r]-pre2[l-1];
		tot0=r-l+1-tot1;
	}
	else{
		tot1=pre1[r]-pre1[l-1];
		tot0=r-l+1-tot1;	
	}
//	cout << l << " " << r << " " << tot0 << " " << tot1 << " " << fir.num0 << " " << fir.num1 << endl;
	get_ans(tot1,tot0,fir,ans);
	if(fir.ed<=sec.st-1){fir.init();return;}
	if(fir.ed<=sec.ed){
		tot1=fir.num1,tot0=fir.num0;
		get_ans(tot1,tot0,sec,ans);
		fir.init();
	}
	else{
		tot1=sec.num1,tot0=sec.num0;
//		cout << tot1 << " " << tot0 << endl;
		get_ans(tot1,tot0,fir,ans);
		sec.init();
	}
//	cout << ans << " " << fir.num0 << " " << fir.num1 << endl;
	return;
}
void init(int n){
	cnt1=cnt2=0;
	for (int i=1;i<=n;i++) pre1[i]=pre2[i]=0;
	return;	
}
#define inf 0x3f3f3f3f
void solve(){
	int n,ans=0;
	cin >> n;
	init(n);
	cin >> s1+1;
	cin >> s2+1;
	cin >> t1+1;
	cin >> t2+1;
	for (int i=1;i<=n;i++) pre1[i]=pre1[i-1]+s1[i]-'0',pre2[i]=pre2[i-1]+s2[i]-'0';
	int last=0;
	t1[n+1]='0';
	t2[n+1]='0';
	for (int i=1;i<=n+1;i++){
		if(t1[i]=='0'){
			if(i-last+1<3){last=i;continue;}
			num1[++cnt1]=(node){last+1,i-1,i-last-1-(pre1[i-1]-pre1[last]),pre1[i-1]-pre1[last],1};
			last=i;
		}
	}
	last=0;
	for (int i=1;i<=n+1;i++){
		if(t2[i]=='0'){
			if(i-last+1<3){last=i;continue;}
			num2[++cnt2]=(node){last+1,i-1,i-last-1-(pre2[i-1]-pre2[last]),pre2[i-1]-pre2[last],2};
			last=i;
		}
	}
	for (int i=1;i<=n;i++){
		if(t1[i]=='0'&&t2[i]=='0'&&s1[i]==s2[i]) ans++; 	
	}
//	cout << ans << endl;
//	for (int i=1;i<=cnt1;i++) cout << num1[i].st << " " << num1[i].ed << " " << num1[i].num0 << " " << num1[i].num1 << endl;
//	for (int i=1;i<=cnt2;i++) cout << num2[i].st << " " << num2[i].ed << " " << num2[i].num0 << " " << num2[i].num1 << endl;
	int i=1,j=1;
	while(i<=cnt1&&j<=cnt2){
		node mx,mn;
		if(num1[i].st>=num2[j].st) mx=num1[i],mn=num2[j];
		else mx=num2[j],mn=num1[i];
//		cout << "HERE" << endl;
//		cout << ans << " " << i << " " << j << endl;
//		cout << num2[j].num0 << " " << num2[j].num1 << endl;
//		cout << ans << " " << num2[1].st << " " << num2[1].ed << endl;
		solve(mn,mx,ans);
		if(mx.id==1) num1[i]=mx;
		else num2[j]=mx;
		if(mn.id==1) num1[i]=mn;
		else num2[j]=mn;
		if(num1[i].empty()) i++;
		if(num2[j].empty()) j++;	
//		cout << mn.num0 << " " << mn.num1 << endl;
//		cout << mx.num0 << " " << mn.num1 << endl;
	}
	while(i<=cnt1){
		node tmp=(node){inf,inf,0,0,2};
		node nw=num1[i];
		solve(nw,tmp,ans);
		i++;	
	}
	while(j<=cnt2){
		node tmp=(node){inf,inf,0,0,1};
		node nw=num2[j];
		solve(nw,tmp,ans);
		j++;	
	}
	cout << ans << 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();
	return 0;
}
/*
10
10
0110111100
1111111100
1110000100
0110111011
9
101111111
100111000
110111011
011111111
*/
