#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define MP make_pair
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N=2e5+10,M=1e6+10,mod=998244353;
int n;
char s[2][N],t[2][N];
struct Node{int l,r,c[2];};
vector<Node> A,B;
void solve(){
	cin>>n;
	cin>>(s[0]+1)>>(s[1]+1);
	cin>>(t[0]+1)>>(t[1]+1);
	int ans=0;
	A.clear(),B.clear();
	Node u=(Node){1,0};
	u.c[0]=u.c[1]=0;
	for(int i=1;i<=n;i++){
		if(t[0][i]=='1') u.c[s[0][i]-'0']++;
		else{
			u.r=i-1;
			if(u.l<=u.r) A.pb(u);
			u.l=i,u.r=i,u.c[0]=u.c[1]=0;
			u.c[s[0][i]-'0']++;
			A.pb(u);
			u.l=i+1,u.c[0]=u.c[1]=0;
		}
	}
	u.r=n;
	if(u.l<=u.r) A.pb(u);
	//
	u=(Node){1,0};
	u.c[0]=u.c[1]=0;
	for(int i=1;i<=n;i++){
		if(t[1][i]=='1') u.c[s[1][i]-'0']++;
		else{
			u.r=i-1;
			if(u.l<=u.r) B.pb(u);
			u.l=i,u.r=i,u.c[0]=u.c[1]=0;
			u.c[s[1][i]-'0']++;
			B.pb(u);
			u.l=i+1,u.c[0]=u.c[1]=0;
		}
	}
	u.r=n;
	if(u.l<=u.r) B.pb(u);
	for(int i=0,j=0;i<(int)A.size();i++){
		while(j<(int)B.size()&&B[j].r<A[i].l) ++j;
		while(j<(int)B.size()&&B[j].l<=A[i].r){
			int lim=min(A[i].r-A[i].l+1,B[j].r-B[j].l+1);
			lim=min(lim,A[i].r-B[j].l+1);
			lim=min(lim,B[j].r-A[i].l+1);
			int res=min(lim,min(A[i].c[0],B[j].c[0]));
			ans+=res;
			A[i].c[0]-=res,B[j].c[0]-=res;
			res=min(lim,min(A[i].c[1],B[j].c[1]));
			ans+=res;
			A[i].c[1]-=res,B[j].c[1]-=res;
			j++;
		}
		if(j) --j;
	}
	cout<<ans<<'\n';
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--) solve();
	return 0;
}
