#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define de(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const ll N=1e5+50,M=+50,L=0;
const ll inf=1e9,P=0;
ll read(){
	ll x=0,f=0;char c=getchar();
	while(c<'0'||c>'9') f|=(c=='-'),c=getchar();
	while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();
	return f?-x:x;
}
struct Ran{int l,r,cnt0,cnt1;};
int n,cnt,T;
int f1[N],f2[N];
char s1[N],s2[N],c1[N],c2[N];
Ran rn[N];
void work(){
	n=read();
	scanf("%s%s%s%s",s1+1,s2+1,c1+1,c2+1);
	fo(i,1,n) f1[i]=c1[i]-'0',f2[i]=c2[i]-'0';
	fo(i,1,n){
		int j=i;
		Ran now={i,0,s2[i]=='0',s2[i]=='1'};
		while(j+1<=n&&f2[j]&&f2[j+1]){
			j++;
			if(s2[j]=='0') now.cnt0++;
			else now.cnt1++;
		}
		now.r=j,i=j;
		rn[++cnt]=now;
	}
	reverse(rn+1,rn+1+cnt);
//	fo(i,1,cnt) cout<<rn[i].cnt0<<" "<<rn[i].cnt1<<endl;
	int ans=0;
	fo(i,1,n){
		int j=i,cnt0=s1[i]=='0',cnt1=s1[i]=='1';
		while(j+1<=n&&f1[j]&&f1[j+1]){
			j++;
			if(s1[j]=='0') cnt0++;
			else cnt1++;
		}
		while(cnt&&rn[cnt].r<i) cnt--;
		while(cnt&&rn[cnt].l<=j){
			int sme0=min(rn[cnt].cnt0,cnt0);
			int sme1=min(rn[cnt].cnt1,cnt1);
			int len=min(j,rn[cnt].r)-max(i,rn[cnt].l)+1;
			ans+=sme0+sme1;			
			rn[cnt].cnt0-=sme0,cnt0-=sme0;
			rn[cnt].cnt1-=sme1,cnt1-=sme1;			

			int dt=len-sme0-sme1;
//			if(sme0+sme1!=len) cout<<"F";
			if(rn[cnt].cnt0) rn[cnt].cnt0-=dt;
			else if(rn[cnt].cnt1) rn[cnt].cnt1-=dt;		
			if(cnt0) cnt0-=dt;
			else if(cnt1) cnt1-=dt;			
//			if(T==3) cout<<i<<' '<<j<<" "<<cnt0<<" "<<cnt1<<" "<<rn[cnt].l<<" "<<rn[cnt].r<<" "<<rn[cnt].cnt0<<" "<<rn[cnt].cnt1<<" "<<sme0<<" "<<sme1<<" "<<dt<<" "<<endl;			
			if(rn[cnt].r<=j) cnt--;
			else break;
		}
		i=j;
	}
	printf("%d\n",ans);
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	T=read();
	while(T--){
		cnt=0;
		work();
	}
	return 0;
}
