#include<bits/stdc++.h>
#define pii pair<int,int>
const int N=1e5+3;
using namespace std;
int n,S1[N],S2[N]; pii a[N],b[N];
string s1,s2,t1,t2;
void Solve(){
	cin>>n; int zcro=0,ones=0;
	cin>>s1>>s2>>t1>>t2;
	for(int i=0;i<n;++i){
		S1[i]=S2[i]=0;
		a[i]={0,0};
		b[i]={0,0};
	}
	for(int i=0;i<n;++i){
		if(t1[i]=='0'){
			if(i)a[i-1]={zcro,ones};
			zcro=0; ones=0;
			S1[i]=s1[i]-'0';
		} else {
			S1[i]=2;
			if(s1[i]=='0')++zcro;
			else ++ones;
		}
	} if(t1[n-1]=='1'){
		a[n-1]={zcro,ones};
		zcro=0; ones=0;
	}
	
	for(int i=0;i<n;++i){
		if(t2[i]=='0'){
			if(i)b[i-1]={zcro,ones};
			zcro=0; ones=0;
			S2[i]=s2[i]-'0';
		} else {
			S2[i]=2;
			if(s2[i]=='0')++zcro;
			else ++ones;
		}
	} if(t2[n-1]=='1'){
		b[n-1]={zcro,ones};
		zcro=0; ones=0;
	}
	
	int zcro1=0; int ones1=0;
	int zcro2=0; int ones2=0;
	reverse(a,a+n);
	reverse(b,b+n);
	reverse(S1,S1+n);
	reverse(S2,S2+n);
	int ans=0;
	for(int i=0;i<n;++i){
		zcro1+=a[i].first;
		zcro2+=b[i].first;
		ones1+=a[i].second;
		ones2+=b[i].second;
		if(S1[i]!=2 && S2[i]!=2){
			if(S1[i]==S2[i])++ans;
		} else if(S1[i]!=2 && S2[i]==2){
			if(S1[i]==1){
				if(ones2)--ones2,++ans;
				else --zcro2;
			} else {
				if(zcro2)--zcro2,++ans;
				else --ones2;
			}
		} else if(S1[i]==2 && S2[i]!=2){
			if(S2[i]==1){
				if(ones1)--ones1,++ans;
				else --zcro1;
			} else {
				if(zcro1)--zcro1,++ans;
				else --ones1;
			}
		} else {
			int u=min(zcro1,zcro2);
			int v=min(ones1,ones2);
			int U=max(zcro1,zcro2);
			int V=max(ones1,ones2);
			if(u>v){
				--zcro1;
				--zcro2;
				++ans;
			} else if(u<v){
				--ones1;
				--ones2;
				++ans;
			} else {
				if(u==0){
					if(zcro1)--zcro1;
					else --zcro2;
					if(ones1)--ones1;
					else --ones2;
				} else {
					if(U>V){
						--zcro1;
						--zcro2;
						++ans;
					} else {
						--ones1;
						--ones2;
						++ans;
					}
				}
			}
		}
	}
	cout<<ans<<'\n';
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); int Ks;
	cin>>Ks; while(Ks--)Solve();
	return 0;
}
