#include<bits/stdc++.h>
using namespace std;
int n,t,A,B,C,ans,sum,qw,wq;
string x,y,l,r;
void dfs(int xx){
	if(xx==n-1){
		sum=0;
		for(int i=0;i<x.size();i++){
			if(x[i]==y[i]) sum++;
		}
		ans=max(ans,sum);
		return;
	}
	dfs(xx+1);
	if(l[xx]!='0'&&l[xx+1]!='0'){
		swap(x[xx],x[xx+1]);
		dfs(xx+1);
		swap(x[xx],x[xx+1]);
	}
	dfs(xx+1);
	if(r[xx]!='0'&&r[xx+1]!='0'){
		swap(y[xx],y[xx+1]);
		dfs(xx+1);
		swap(y[xx],y[xx+1]);
	}
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>t;
	while(t--){
		ans=A=B=C=qw=wq=0;
		cin>>n;
		cin>>x>>y>>l>>r;
		for(int i=1;i<n;i++){
			if(x[i-1]!=x[i]){
				A=1;
				break;
			}
		}
		for(int i=0;i<n;i++){
			if(l[i]=='0') qw++;
			if(r[i]=='0') wq++;
		}
		if(qw!=wq||qw!=1) C=1;
		if(l!=r) B=1;
		if(!A){
			for(int i=0;i<n;i++){
				if(x[i]==y[i]) ans++;
			}
			cout<<ans<<"\n";
			continue;
		}
		if(!B){
			l+='0',r+='0';
			int lx=0,rx=0,ly=0,ry=0;
			for(int i=0;i<l.size();i++){
				if(l[i]=='0'){
					ans+=min(lx,ly)+min(rx,ry);
					lx=ly=rx=ry=0;
					if(x[i]==y[i]&&i!=n) ans++;
				}
				else{
					if(x[i]=='1') lx++;
					else rx++;
					if(y[i]=='1') ly++;
					else ry++;
				}
			}
			cout<<ans<<"\n";
			continue;
		}
		if(n<=10){
			dfs(0);
			cout<<ans<<"\n";
			continue;
		}
		if(!C){
			for(int i=0;i<n;i++){
				if(l[i]=='0') qw=i;
				if(r[i]=='0') wq=i;
			}
			if(qw>wq){
				int lx=0,rx=0,ly=0,ry=0;
				for(int i=0;i<qw;i++){
					if(x[i]=='1') lx++;
					else rx++;
				}
				for(int i=0;i<=wq;i++){
					if(y[i]=='1') ly++;
					else ry++;
				}
				ans+=min(lx,ly)+min(rx,ry);
				if(lx<ly) rx=rx+lx-ly-ry,lx=0;
				else if(rx<ry) lx=lx+rx-ry-ly,rx=0;
				else lx-=ly,rx-=ry;
				//cout<<lx<<" "<<rx<<"\n";
				int lxx=0,rxx=0,lyy=0,ryy=0;
				for(int i=qw;i<n;i++){
					if(x[i]=='1') lxx++;
					else rxx++;
				}
				for(int i=wq+1;i<n;i++){
					if(y[i]=='1') lyy++;
					else ryy++;
				}
				ans+=min(lxx,lyy)+min(rxx,ryy);
				if(lxx>lyy) ryy=ryy+lyy-lxx-rxx,lyy=0;
				else if(rxx>ryy) lyy=lyy+ryy-rxx-lxx,ryy=0;
				else lyy-=lxx,ryy-=rxx;
				//cout<<lyy<<" "<<ryy<<"\n";
				ans+=min(ryy,rx)+min(lyy,lx);
			}
			else{
				int lx=0,rx=0,ly=0,ry=0;
				for(int i=0;i<=qw;i++){
					if(x[i]=='1') lx++;
					else rx++;
				}
				for(int i=0;i<wq;i++){
					if(y[i]=='1') ly++;
					else ry++;
				}
				ans+=min(lx,ly)+min(rx,ry);
				if(lx>ly) ry=ry+ly-lx-rx,ly=0;
				else if(rx>ry) ly=ry+ly-lx-rx,ry=0;
				else ly-=lx,ry-=rx;
				//cout<<ly<<" "<<ry<<"\n";
				int lxx=0,rxx=0,lyy=0,ryy=0;
				for(int i=qw+1;i<n;i++){
					if(x[i]=='1') lxx++;
					else rxx++;
				}
				for(int i=wq;i<n;i++){
					if(y[i]=='1') lyy++;
					else ryy++;
				}
				ans+=min(lxx,lyy)+min(rxx,ryy);
				if(lxx<lyy) rxx=rxx+lxx-lyy-ryy,lxx=0;
				else if(rxx<ryy) lxx=rxx+lxx-lyy-ryy,rxx=0;
				else lxx-=lyy,rxx-=ryy;
				//cout<<lxx<<" "<<rxx<<"\n";
				ans+=min(ry,rxx)+min(ly,lxx);
			}
			cout<<ans<<"\n";
			continue;
		}
		cout<<n<<"\n";
	}
	return 0;
}
