#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define MP make_pair
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
typedef long long ll;
using namespace std;

int read(){
	int s=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')f^=(c=='-'),c=getchar();
	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
	return f?s:-s;
}

const int N=100005;
int n,ts,tt,cs[N][2],ct[N][2],ans;
char s1[N],s2[N],t1[N],t2[N];
pii rs[N],rt[N];

signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	for(int T=read();T--;){
		n=read();
		rep(i,1,n)rep(j,0,1)cs[i][j]=ct[i][j]=0;
		scanf("%s%s%s%s",s1+1,s2+1,t1+1,t2+1);
		ts=tt=ans=0;
		int L=1;
		rep(i,1,n+1){
			if(i==n+1||t1[i]=='0'||t1[i-1]=='0'){
				ts++;
				rs[ts]=MP(L,i-1);
				rep(j,L,i-1)cs[ts][s1[j]-'0']++;
				L=i;
			}
		}
		L=1;
		rep(i,1,n+1){
			if(i==n+1||t2[i]=='0'||t2[i-1]=='0'){
				tt++;
				rep(j,L,i-1)ct[tt][s2[j]-'0']++;
				rt[tt]=MP(L,i-1);
				L=i;
			}
		}
		int curs=1,curt=1;
		while(curs<=ts&&curt<=tt){
			int len=min(rs[curs].se,rt[curt].se)-max(rs[curs].fi,rt[curt].fi)+1;
			rep(i,0,1){
				int tmp=min(cs[curs][i],ct[curt][i]);
				tmp=min(tmp,len);
//				printf("%d %d %d %d\n",rs[curs].se,rt[curt].se,i,tmp);
				cs[curs][i]-=tmp,ct[curt][i]-=tmp,ans+=tmp;
			}
			if(rs[curs].se==rt[curt].se)curs++,curt++;
			else if(rs[curs].se<rt[curt].se)curs++;
			else curt++;
		}
		printf("%d\n",ans);
	}
	return 0;
}
