#include<iostream>
#include<cstdlib>
#define ls p*2
#define rs p*2+1
using namespace std;
const int N=100005;
int T,n,ans;
char a[N],b[N],t1[N],t2[N];
int cya[N],cyb[N],qzha[N],qzhb[N];
struct tree{
	int l,r,sum1,sum0;
}ta[4*N],tb[4*N];

void build(int p,int l,int r,tree *t,char *aa){
	t[p].l=l,t[p].r=r;
	if(l==r){
		t[p].sum0=(aa[l-1]=='0');
		t[p].sum1=(aa[l-1]=='1');
		return;
	}
	int mid=l+r>>1;
	build(ls,l,mid,t,aa);
	build(rs,mid+1,r,t,aa);
	t[p].sum0=t[ls].sum0+t[rs].sum0;
	t[p].sum1=t[ls].sum1+t[rs].sum1;
}
int ask1(int p,int l,int r,tree *t){
	if(l<=t[p].l&&r>=t[p].r){
		return t[p].sum1;
	}
	int anss=0;
	int mid=t[p].l+t[p].r>>1;
	if(mid>=l){
		anss+=ask1(ls,l,r,t);
	}
	if(mid<r){
		anss+=ask1(rs,l,r,t);
	}
	return anss;
}

int ask0(int p,int l,int r,tree *t){
	if(l<=t[p].l&&r>=t[p].r){
		return t[p].sum0;
	}
	int anss=0;
	int mid=t[p].l+t[p].r>>1;
	if(mid>=l){
		anss+=ask0(ls,l,r,t);
	}
	if(mid<r){
		anss+=ask0(rs,l,r,t);
	}
	return anss;
}

void change1(int p,int l,int r, tree *t){
	if(l<=t[p].l&&r>=t[p].r){
		t[p].sum1--;
		return;
	}
	int anss=0;
	int mid=t[p].l+t[p].r>>1;
	if(mid>=l){
		change1(ls,l,r,t);
	}
	if(mid<r){
		change1(rs,l,r,t);
	}
	t[p].sum1=t[ls].sum1+t[rs].sum1;
	return;
}

void change0(int p,int l,int r,tree *t){
	if(l<=t[p].l&&r>=t[p].r){
		t[p].sum0--;
		return;
	}
	int anss=0;
	int mid=t[p].l+t[p].r>>1;
	if(mid>=l){
		change0(ls,l,r,t);
	}
	if(mid<r){
		change0(rs,l,r,t);
	}
	t[p].sum0=t[ls].sum0+t[rs].sum0;
	return;
}

int getshu(int l,int r,int *qzh){
	if(l!=0)
	return qzh[r]-qzh[l-1];
	else{
		return qzh[r];
	}
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n;
		cin>>a>>b>>t1>>t2;
		ans=0;
		int cnt1=0,cnt2=0;
		for(int i=n;i>=0;i--){
			if(t1[i]=='1'){
				cnt1++;
			}
			else{
				cnt1=0;
			}
			cya[i]=cnt1;
			if(t2[i]=='1'){
				cnt2++;
			}
			else{
				cnt2=0;
			}
			cyb[i]=cnt2;
		}
		for(int i=0;i<n;i++){
			int temp;
			if(cya[i]!=1 && cya[i]!=0){
				temp=cya[i];
				while(cya[i+1]!=0){
					cya[++i]=temp;
				}
			}
			else{
				cya[i]=0;
			}
		}
		for(int i=0;i<n;i++){
			int temp;
			if(cyb[i]!=1 && cyb[i]!=0){
				temp=cyb[i];
				while(cyb[i+1]!=0){
					cyb[++i]=temp;
				}
			}
			else{
				cyb[i]=0;
			}
		}
		qzha[0]=a[0]-'0';
		qzhb[0]=b[0]-'0';
		for(int i=1;i<n;i++){
			qzha[i]=qzha[i-1]+(a[i]-'0');
		}
		for(int i=1;i<n;i++){
			qzhb[i]=qzhb[i-1]+(b[i]-'0');
		}
//		for(int i=0;i<n;i++){
//			cout<<cya[i]<<" ";
//		}cout<<endl;
//		for(int i=0;i<n;i++){
//			cout<<cyb[i]<<" ";
//		}cout<<endl;
		//cout<<getshu(0,2,qzha);
		build(1,1,n,ta,a);
		build(1,1,n,tb,b);
		int qja=0,qjb=0;
		for(int i=0;i<n;i++){
			if(!cya[i]&&!cyb[i]){
				ans+=(a[i]==b[i]);
				qjb=0,qja=0;
			}
			else if(!cya[i]){
				qjb++,qja=0;
				int bqjl=i-qjb+2,bqjr=i-qjb+2+cyb[i]-1,aqjl=i-qja+2,aqjr=i-qja+2+cya[i]-1;
				if(a[i]=='1'){
					if(ask1(1,bqjl,bqjr,tb)>=1){
						ans++;
						change1(1,i+1,i+1,tb);
					}
				}
				else{
					if(ask0(1,bqjl,bqjr,tb)>=1){
						ans++;
						change0(1,i+1,i+1,tb);
					}
				}
			}
			else if(!cyb[i]){
				qja++,qjb=0;
				int bqjl=i-qjb+2,bqjr=i-qjb+2+cyb[i]-1,aqjl=i-qja+2,aqjr=i-qja+2+cya[i]-1;
				if(b[i]=='1'){
					if(ask1(1,aqjl,aqjr,ta)>=1){
						ans++;
						change1(1,i+1,i+1,ta);
					}
				}
				else{
					if(ask0(1,aqjl,aqjr,ta)>=1){
						ans++;
						change0(1,i+1,i+1,ta);
					}
				}
			}
			else{
				qja++,qjb++;
				int bqjl=i-qjb+2,bqjr=i-qjb+2+cyb[i]-1,aqjl=i-qja+2,aqjr=i-qja+2+cya[i]-1;
				if(ask0(1,bqjl,bqjr,tb)>0&&ask0(1,aqjl,aqjr,ta)>0){
					ans++;
					change0(1,i+1,i+1,ta);
					change0(1,i+1,i+1,tb);
				}
				else if(ask1(1,bqjl,bqjr,tb)>0&&ask1(1,aqjl,aqjr,ta)>0){
					ans++;
					change1(1,i+1,i+1,ta);
					change1(1,i+1,i+1,tb);
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
