#include<bits/stdc++.h>
using namespace std;
int T;
int n,ans,cnts0,cnts1,cntss0,cntss1,cnt0,cnt1,p,pp;
string s,ss,t,tt;
void getp(){
	int st=p;
	for(int i=st+1;i<n;i++){
		if(t[i]=='0'){
			p=i;	break;
		}
		if(s[i]=='0')	cnts0++;
		if(s[i]=='1')	cnts1++;
	}
	if(p==st)	p=n;
}
void getpp(){
	int st=pp;
	for(int i=st+1;i<n;i++){
		if(tt[i]=='0'){
			pp=i;	break;
		}
		if(ss[i]=='0')	cntss0++;
		if(ss[i]=='1')	cntss1++;
	}
	if(pp==st)	pp=n;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);	cout.tie(0);
	cin>>T;
	while(T--){
		cin>>n;
		cin>>s>>ss>>t>>tt;
		ans=0;
		p=n,pp=n;
		for(int i=0;i<n;i++){
			if(t[i]=='0'){
				p=i;	break;
			}
			if(s[i]=='0')	cnts0++;
			if(s[i]=='1')	cnts1++;
		}
		for(int i=0;i<n;i++){
			if(tt[i]=='0'){
				pp=i;	break;
			}
			if(ss[i]=='0')	cntss0++;
			if(ss[i]=='1')	cntss1++;
		}
		while(p<n||pp<n){
			ans+=min(cnts0,cntss0)+min(cnts1,cntss1);
			cnt0=min(cnts0,cntss0),cnt1=min(cnts1,cntss1);
			cnts0-=cnt0,cntss0-=cnt0;
			cnts1-=cnt1,cntss1-=cnt1;
			if(p==pp){
				if(s[p]==ss[pp])	ans++;
				cnts0=cntss0=cnts1=cntss1=0;
				getp();		getpp();
				continue ;
			}
			if(p<pp){
				if(!cntss0)		cntss1-=cnts0;
				if(!cntss1)		cntss0-=cnts1;
				if(s[p]=='0'){
					if(cntss0)	ans++,cntss0--;
					else	cntss1--;
				}else{
					if(cntss1)	ans++,cntss1--;
					else	cntss0--;
				}
				cnts0=cnts1=0;
				getp();
				continue ;
			}
			if(p>pp){
				if(!cnts0)		cnts1-=cntss0;
				if(!cnts1)		cnts0-=cntss1; 
				if(ss[pp]=='0'){
					if(cnts0)	ans++,cnts0--;
					else	cnts1--;
				}else{
					if(cnts1)	ans++,cnts1--;
					else	cnts0--;
				}
				cntss0=cntss1=0;
				getpp();
				continue ;
			}
		}
		ans+=min(cnts0,cntss0)+min(cnts1,cntss1);
		cnts0=cnts1=cntss0=cntss1=0;
		cout<<ans<<"\n";
	}
	return 0;
}
