#include<bits/stdc++.h>
using namespace std;
const int NUM=1e5+6;
int n;
pair<int,int> a[NUM],b[NUM];
int ab[NUM],ba[NUM];
void solve(){
	int n,cnta=0,cntb=0; cin>>n;
	for(int i=1;i<=n;i++){
		ab[i]=0; ba[i]=0;
	}
	string s1,s2; cin>>s1>>s2;
	s1=" "+s1; s2=" "+s2;
	string x1,x2; cin>>x1>>x2;
	x1=" "+x1; x2=" "+x2;
	int sum10=0,sum11=0,sum20=0,sum21=0;
	for(int i=1;i<=n;i++){
		if(x1[i]=='1'){
			if(s1[i]=='1') sum11++;
			else sum10++;
		//	if(i==n) a[++cnta]={sum11,sum10};
		}
		else{
			if(sum11+sum10!=0){
				a[++cnta]={sum11,sum10};
				sum11=0; sum10=0;
			}
		}
		if(x2[i]=='1'){
			if(s2[i]=='1') sum21++;
			else sum20++;
		//	if(i==n) b[++cntb]={sum21,sum20};
		}
		else{
			if(sum21+sum20!=0){
				b[++cntb]={sum21,sum20};
				sum21=0; sum20=0;
			}	
		}
		if(x1[i]=='1') ba[i]=cnta+1;
		if(x2[i]=='1') ab[i]=cntb+1;
		if(i==n){
			if(x1[i]=='1') a[++cnta]={sum11,sum10};
			if(x2[i]=='1') b[++cntb]={sum21,sum20};
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(x1[i]=='0'&&x2[i]=='0') ans+=(s1[i]==s2[i]);
		else if(x1[i]=='0'){
			if(s1[i]=='1'){
				if(b[ab[i]].first){
					ans++; b[ab[i]].first--;
				}
			}
			else{
				if(b[ab[i]].second){
					ans++; b[ab[i]].second--;
				}
			}
		}
		else if(x2[i]=='0'){
			if(s2[i]=='1'){
				if(a[ba[i]].first){
					ans++; a[ba[i]].first--;
				}
			}
			else{
				if(a[ba[i]].second){
					ans++; a[ba[i]].second--;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(x1[i]=='1'&&x2[i]=='1'){
			if(a[ba[i]].first&&b[ab[i]].first){
				int val=min(a[ba[i]].first,b[ab[i]].first);
				ans+=val;
				a[ba[i]].first-=val; b[ab[i]].first-=val;
			}
			if(a[ba[i]].second&&b[ab[i]].second){
				int val=min(a[ba[i]].second,b[ab[i]].second);
				ans+=val;
				a[ba[i]].second-=val; b[ab[i]].second-=val;
			}
		}
	}
	cout<<ans<<"\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t; cin>>t;
	while(t--) solve();
	return 0;
}
