#include <bits/stdc++.h>
using namespace std;
const int M=1e5+5;
int lcy1[M],noip[M],coby1[M],kunkuakcsp[M],ptr1,akcsp[M][2],hsfz[M],manoip[M];
int lcy2[M],csmo[M],coby2[M],kunkuakimo[M],ptr2,akimo[M][2],szzx[M],macsmo[M];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;cin>>T;
	while(T--){
		int n;cin>>n;
		string s;
		cin>>s;for(int i=1;i<=n;i++)lcy1[i]=s[i-1]-48;
		cin>>s;for(int i=1;i<=n;i++)lcy2[i]=s[i-1]-48;
		cin>>s;for(int i=1;i<=n;i++)noip[i]=s[i-1]-48;
		cin>>s;for(int i=1;i<=n;i++)csmo[i]=s[i-1]-48;
		
		for(int i=1;i<=n;i++){
			if(noip[i]==1){
				if(noip[i-1]==0)coby1[++ptr1]=i;
				kunkuakcsp[ptr1]=i;hsfz[i]=ptr1;
			}
		}
		
		for(int i=1;i<=n;i++){
			if(csmo[i]==1){
				if(csmo[i-1]==0)coby2[++ptr2]=i;
				kunkuakimo[ptr2]=i;szzx[i]=ptr2;
			}
		}
		
		for(int i=1;i<=ptr1;i++)for(int j=coby1[i];j<=kunkuakcsp[i];j++)akcsp[i][lcy1[j]]++; 
		
		for(int i=1;i<=ptr2;i++)for(int j=coby2[i];j<=kunkuakimo[i];j++)akimo[i][lcy2[j]]++; 
		
		int ans=0;
		
		for(int i=1;i<=n;i++){
			int i1=hsfz[i],i2=szzx[i];
			if(i1==0&&i2==0)ans+=(lcy1[i]==lcy2[i]);
			if(i1==0&&i2!=0){
				if(akimo[i2][lcy1[i]])akimo[i2][lcy1[i]]--,ans++;
				else akimo[i2][1-lcy1[i]]--;
			}
			if(i1!=0&&i2==0){
				if(akcsp[i1][lcy2[i]])akcsp[i1][lcy2[i]]--,ans++;
				else akcsp[i1][1-lcy2[i]]--;
			}
		}
		
		int x=1,y=1,cur;
		while(1){			
			if(kunkuakcsp[x]<kunkuakimo[y]){
				if(akcsp[x][0]>akimo[y][0]){
					ans+=akimo[y][0];
					akcsp[x][0]-=akimo[y][0];
					akimo[y][1]-=akcsp[x][0];
					akimo[y][0]=akcsp[x][0]=0;
				}else{
					ans+=akcsp[x][0];
					akimo[y][0]-=akcsp[x][0];
					akcsp[x][0]=0;
				}
				if(akcsp[x][1]>akimo[y][1]){
					ans+=akimo[y][1];
					akcsp[x][1]-=akimo[y][1];
					akimo[y][0]-=akcsp[x][1];
					akimo[y][1]=0;
				}else{
					ans+=akcsp[x][1];
					akimo[y][1]-=akcsp[x][1];
					akcsp[x][1]=0;
				}
				manoip[x]=1;
			}
			
			if(kunkuakcsp[x]>kunkuakimo[y]){
				if(akimo[y][0]>akcsp[x][0]){
					ans+=akcsp[x][0];
					akimo[y][0]-=akcsp[x][0];
					akcsp[x][1]-=akimo[y][0];
					akimo[y][0]=akcsp[x][0]=0;
				}else{
					ans+=akimo[y][0];
					akcsp[x][0]-=akimo[y][0];
					akimo[y][0]=0;
				}
				if(akimo[y][1]>akcsp[x][1]){
					ans+=akcsp[x][1];
					akimo[y][1]-=akcsp[x][1];
					akcsp[x][0]-=akimo[y][1];
					akimo[y][1]=akcsp[x][1]=0;
				}else{
					ans+=akimo[y][1];
					akcsp[x][1]-=akimo[y][1];
					akimo[y][1]=0;
				}
				macsmo[y]=1;
			}
			
			if(kunkuakcsp[x]==kunkuakimo[y]){
				ans+=min(akcsp[x][0],akimo[y][0]);
				ans+=min(akcsp[x][1],akimo[y][1]);
				
				manoip[x]=macsmo[y]=1;
			}
			
			if(manoip[x])x++;
			if(macsmo[y])y++;
//			cout<<x<<' '<<y<<' '<<ans<<" "<<akimo[y][0]<<' '<<akimo[y][1]<<endl;
			if(x>ptr1||y>ptr2)break;
		}
		cout<<ans<<endl;
		ptr1=ptr2=0;
		for(int i=0;i<M;i++){
			lcy1[i]=noip[i]=coby1[i]=kunkuakcsp[i]=akcsp[i][1]=akcsp[i][0]=hsfz[i]=manoip[i]=0;
			lcy2[i]=csmo[i]=coby2[i]=kunkuakimo[i]=akimo[i][1]=akimo[i][0]=szzx[i]=macsmo[i]=0;
		}
	}
	return 0;
}
