#include<bits/stdc++.h>
using namespace std;
int T,n,ans;
int abl[100005],abl1[100005],abl0[1000005],cnta,sta[100005],eda[100005];
int bbl[100005],bbl1[100005],bbl0[1000005],cntb,tmp,k;
vector<int>ato[100005];
string s1,s2,t1,t2;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>T;
	while(T--){
		cnta=cntb=ans=0;
		cin>>n;
		cin>>s1>>s2>>t1>>t2;
		for(int i=0;i<=n;i++)while(ato[i].size()>0)ato[i].pop_back(); 
		for(int i=0;i<=n;i++)abl[i]=bbl[i]=abl1[i]=abl0[i]=bbl1[i]=bbl0[i]=0;
		for(int i=0;i<=n;i++)sta[i]=eda[i]=0;
		bool flag=0;
		for(int i=0;i<n;i++){
			if(t1[i]=='0'){
				if(flag)eda[cnta]=i-1;
				flag=0;
				abl[i]=++cnta;
				sta[cnta]=eda[cnta]=i;
				if(s1[i]=='1')abl1[cnta]++;
				else abl0[cnta]++;
			}
			else{
				if(!flag)flag=1,cnta++,sta[cnta]=i;
				abl[i]=cnta;
				if(s1[i]=='1')abl1[cnta]++;
				else abl0[cnta]++;
			}
		}
		if(eda[cnta]==0)eda[cnta]=n-1;
		flag=0;
		for(int i=0;i<n;i++){
			if(t2[i]=='0'){
				flag=0;
				bbl[i]=++cntb;
				if(s2[i]=='1')bbl1[cntb]++;
				else bbl0[cntb]++;
			}
			else{
				if(!flag)flag=1,cntb++;
				bbl[i]=cntb;
				if(s2[i]=='1')bbl1[cntb]++;
				else bbl0[cntb]++;
			}
		}
		for(int i=1;i<=cnta;i++){
			int lst=-1;
			for(int j=sta[i];j<=eda[i];j++){
				if(lst!=bbl[j]){
					lst=bbl[j];
					ato[i].push_back(lst);
				}
			}
		}
		for(int i=1;i<=cnta;i++){
			for(int j=0;j<ato[i].size();j++){
				k=ato[i][j];
				if(abl1[i]>0&&bbl1[k]>0){
					tmp=min(abl1[i],bbl1[k]);
					ans+=tmp;
					abl1[i]-=tmp;
					bbl1[k]-=tmp;
				}
				if(abl0[i]>0&&bbl0[k]>0){
					tmp=min(abl0[i],bbl0[k]);
					ans+=tmp;
					abl0[i]-=tmp;
					bbl0[k]-=tmp;
				}
			}
		}
		cout<<ans<<"\n"; 
	}
	return 0;
}
