#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=1e5+5;
int n,res,at,bt;
int abel[N],bbel[N];
int abkt[N][2],bbkt[N][2];

char astr[N],bstr[N];
char alim[N],blim[N];

void init(){
	res=0;
	for(int i=1;i<=n+1;i++){
		abel[i]=bbel[i]=0;
		abkt[i][0]=bbkt[i][0]=abkt[i][1]=bbkt[i][1]=0;
	}
}

signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin>>T;
	
	for(;T;T--){
		cin>>n;
		cin>>(astr+1);
		cin>>(bstr+1);
		cin>>(alim+1);
		cin>>(blim+1);
		alim[n+1]=blim[n+1]='0';
		astr[n+1]='0';
		bstr[n+1]='1'; 
		init();
		
		at=bt=1;
		for(int i=1;i<=n;i++){
			abel[i]=bt;
			bbel[i]=at;
			abkt[at][astr[i]-'0']++;
			bbkt[bt][bstr[i]-'0']++;
			if(alim[i]=='0'){
				abkt[at][astr[i]-'0']--;
				at++;
				bbel[i]=0;
			}
			if(blim[i]=='0'){
				bbkt[bt][bstr[i]-'0']--;
				bt++;
				abel[i]=0;
			}
		}
		at=bt=1;
		for(int i=1,x,y;i<=n+1;i++){
			if(alim[i]=='0'&&blim[i]=='0'){
				res+=min(abkt[at][0],bbkt[bt][0])+min(abkt[at][1],bbkt[bt][1])+(astr[i]==bstr[i]);
				at++;
				bt++;
			}
			else if(alim[i]=='0'||blim[i]=='0'){
				if(alim[i]=='0'){
					x=min(abkt[at][0],bbkt[abel[i-1]][0]);
					y=min(abkt[at][1],bbkt[abel[i-1]][1]);
					res+=x+y;
					abkt[at][0]-=x;
					bbkt[abel[i-1]][0]-=x;
					abkt[at][1]-=y;
					bbkt[abel[i-1]][1]-=y;
					
					if(bbkt[abel[i]][astr[i]-'0']){
						res++;
						bbkt[abel[i]][astr[i]-'0']--;
					}
					at++;
				}
				else{
					x=min(abkt[bbel[i-1]][0],bbkt[bt][0]);
					y=min(abkt[bbel[i-1]][1],bbkt[bt][1]);
					res+=x+y;
					abkt[bbel[i-1]][0]-=x;
					bbkt[bt][0]-=x;
					abkt[bbel[i-1]][1]-=y;
					bbkt[bt][1]-=y;
					
					if(abkt[bbel[i]][bstr[i]-'0']){
						res++;
						abkt[bbel[i]][bstr[i]-'0']--;
					}
					bt++;
				}
			}
		}
		
		cout<<res<<'\n';
	}
	
	return 0;
} 
