#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5; 
int T;
string s,t,x,y;
int n;
int Ls[N],Rs[N],Lt[N],Rt[N];
int l,r;
int ans=0;
map<int,map<int,int> > M;
vector<int> S0,S1;
vector<pair<int,int> > vec;
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n;
		cin>>s>>t>>x>>y;
		s=" "+s,t=" "+t,x=" "+x,y=" "+y;
		ans=0;
		l=0,r=0;
		M.clear();
		vec.clear();
		S0.clear(),S1.clear();
		for(int i=1;i<=n;i++){
			Ls[i]=Rs[i]=Lt[i]=Rt[i]=i;
		}
		for(int i=1;i<=n;i++){
			if(l==0&&x[i]=='1')l=i;
			if(x[i]=='1'&&x[i+1]=='0'){
				vec.push_back(make_pair(l,i));
				l=0;
			}
			if(x[i]=='1'&&i==n)vec.push_back(make_pair(l,i));
		}
		l=0;
		for(auto i:vec){
			for(int j=i.first;j<=i.second;j++)Ls[j]=i.first,Rs[j]=i.second;
		}
		vec.clear();
		for(int i=1;i<=n;i++){
			if(l==0&&y[i]=='1')l=i;
			if(y[i]=='1'&&y[i+1]=='0'){
				vec.push_back(make_pair(l,i));
				l=0;
			}
			if(y[i]=='1'&&i==n)vec.push_back(make_pair(l,i));
		}
		for(int i=1;i<=n;i++){
			if(t[i]=='0')S0.push_back(i);
			else S1.push_back(i);
		}
		
		for(auto i:vec){
			for(int j=i.first;j<=i.second;j++)Lt[j]=i.first,Rt[j]=i.second;
		}
	//	for(int i=1;i<=n;i++)cout<<Ls[i]<<" "<<Rs[i]<<" "<<Lt[i]<<" "<<Rt[i]<<'\n';
		for(int i=1;i<=n;i++){
			if(s[i]=='1'){
				l=Lt[Ls[i]];
				r=Rt[Rs[i]];
				int L=min(Ls[i],Rt[Ls[i]]);
				int R=max(Rs[i],Lt[Rs[i]]);
				
				if(S1.empty()||S1[S1.size()-1]<l)continue;
				auto p=lower_bound(S1.begin(),S1.end(),l);
				//cout<<L<<" "<<R<<" "<<*p<<endl; 
				if(*p<=r){
					if(M[L][R]>=R-L+1)continue;
				else M[L][R]++;
					ans++;
					S1.erase(p);
					continue;
				}
			}
			if(s[i]=='0'){
				l=Lt[Ls[i]];
				r=Rt[Rs[i]];
				int L=min(Ls[i],Rt[Ls[i]]);
				int R=max(Rs[i],Lt[Rs[i]]);
				
				if(S0.empty()||S0[S0.size()-1]<l)continue;
				auto p=lower_bound(S0.begin(),S0.end(),l);
			//	cout<<L<<" "<<R<<" "<<*p<<endl; 
				if(*p<=r){
					if(M[L][R]>=R-L+1)continue;
				else M[L][R]++;
					ans++;
					S0.erase(p);
					continue;
				}
			
			}
		}
		cout<<ans<<"\n";
	}
}
