#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5e5+5;
struct node{
	int l,r,id;
	int cnt1,cnt0;
};
int n,cnt=0;
string s1,s2;
string t1,t2;
int cnt1=0,cnt0=0;
int loc1[N],loc2[N];
void solve(){
	vector<node> vc1,vc2;
	memset(loc1,0,sizeof(loc1));
	memset(loc2,0,sizeof(loc2));
	cnt1=0,cnt0=0; 
	cnt=0;
	cin>>n;
	cin>>s1>>s2;
	cin>>t1>>t2;
	int l=0,r=-1;
	for(int i=0;i<=n-1;i++){
		if(t1[i]=='1'){
			r=max(r+1,l);
			if(s1[i]=='1')cnt1++;
			else cnt0++;
		}
		else{
//			cout<<l<<" "<<r<<endl;
			if(r-l>0)vc1.push_back((node){l,r,++cnt,cnt1,cnt0});
			l=i+1;
			cnt1=0,cnt0=0;
		}
	}
	r=n-1;
	if(r-l>0)vc1.push_back((node){l,r,++cnt,cnt1,cnt0});
	l=0,r=-1,cnt0=cnt1=0,cnt=0;
	for(int i=0;i<=n-1;i++){
		if(t2[i]=='1'){
			r=max(r+1,l);
			if(s2[i]=='1')cnt1++;
			else cnt0++;
		}
		else{
//			cout<<l<<" "<<r<<endl;
			if(r-l>0)vc2.push_back((node){l,r,++cnt,cnt1,cnt0});
			l=i+1;
			cnt1=0,cnt0=0;
		}
	}
	r=n-1;
	if(r-l>0)vc2.push_back((node){l,r,++cnt,cnt1,cnt0});
	for(int i=0;i<vc1.size();i++)
		for(int j=vc1[i].l;j<=vc1[i].r;j++)loc1[j]=vc1[i].id;
	for(int i=0;i<vc2.size();i++)
		for(int j=vc2[i].l;j<=vc2[i].r;j++)loc2[j]=vc2[i].id;
//	for(int i=0;i<n;i++)
//		cout<<loc1[i]<<" ";
//	cout<<"\n";for(int i=0;i<n;i++)
//		cout<<loc2[i]<<" ";
//	cout<<"\n";
	int ans=0;
	for(int i=0;i<vc1.size();i++){
		l=vc1[i].l,r=vc1[i].r,cnt1=vc1[i].cnt1,cnt0=vc1[i].cnt0;
		int k=l;
		while(1){
			while(loc2[k]==0&&k<=r)k++;
			if(k>r)break; 
			node now=vc2[loc2[k]-1];
			int len;
			if(l>=now.l&&r<=now.r)
				len=r-l+1;
			else if(l<=now.l&&r>=now.r)
				len=now.r-now.l+1;
			else if(l>=now.l&&r>=now.r)
				len=now.r-l+1;
			else if(l<=now.l&&r<=now.r)
				len=r-now.l+1;
			int pp=min(len,min(cnt0,now.cnt0)+min(cnt1,now.cnt1));
//			cout<<i+1<<" "<<now.id<<" "<<l<<" "<<r<<" "<<now.l<<" "<<now.r<<" "<<cnt0<<" "<<cnt1<<" "<<now.cnt0<<" "<<now.cnt1<<" "<<len<<" "<<pp<<endl;
			vc1[i].cnt1-=min(len,min(cnt1,now.cnt1));
			vc2[loc2[k]-1].cnt1-=min(len,min(cnt1,now.cnt1));
			len=len-min(len,min(cnt1,now.cnt1));
			vc1[i].cnt0-=min(len,min(cnt0,now.cnt0));
			vc2[loc2[k]-1].cnt0-=min(len,min(cnt0,now.cnt0));
			len=len-min(len,min(cnt0,now.cnt0));
			ans+=pp;
			k=now.r+1;
		}
	}
//	cout<<ans<<endl;
	for(int i=0;i<n;i++){
		if(loc1[i]==0){
			if(loc2[i]==0)
				ans+=(s1[i]==s2[i]);
			else{
				if(s1[i]=='0')
					if(vc2[loc2[i]-1].cnt0>0)
						ans++,vc2[loc2[i]-1].cnt0--;
				if(s1[i]=='1')
					if(vc2[loc2[i]-1].cnt1>0)
						ans++,vc2[loc2[i]-1].cnt1--;
			}
		}
	}
	for(int i=0;i<n;i++){
		if(loc2[i]==0){
			if(loc1[i]!=0){
				if(s2[i]=='0')
					if(vc1[loc1[i]-1].cnt0>0)
						ans++,vc1[loc1[i]-1].cnt0--;
				if(s2[i]=='1')
					if(vc1[loc1[i]-1].cnt1>0)
						ans++,vc1[loc1[i]-1].cnt1--;
			}
		}
	}
	cout<<ans<<"\n";
	return;
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
		solve();
	return 0;
}

