#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
template<class T> int cmn(T &x,T y){return y<x?x=y,1:0;}
template<class T> int cmx(T &x,T y){return y>x?x=y,1:0;}

const int N=2e5+3;
int n,cnt[N][2],bel1[N],bel2[N];
char s1[N],s2[N],t1[N],t2[N]; 
void run(){
	cin>>n>>(s1+1)>>(s2+1)>>(t1+1)>>(t2+1);
	ms(cnt,0);
	int tot=0; 
	F(i,1,n){
		if(t1[i]=='1'){
			int j=i;
			while(j<n&&t1[j+1]=='1') j++;
			tot++;
			F(k,i,j){
				cnt[tot][s1[k]-'0']++;
				bel1[k]=tot;
			}
			i=j;
		}else{
			tot++;
			cnt[tot][s1[i]-'0']++;
			bel1[i]=tot;
		}
	}
	F(i,1,n){
		if(t2[i]=='1'){
			int j=i;
			while(j<n&&t2[j+1]=='1') j++;
			tot++;
			F(k,i,j){
				cnt[tot][s2[k]-'0']++;
				bel2[k]=tot;
			} 
			i=j;
		}else{
			tot++;
			cnt[tot][s2[i]-'0']++;
			bel2[i]=tot;
		}
	}
//	F(i,1,n) cout<<bel1[i]<<" \n"[i==n];
//	F(i,1,n) cout<<bel2[i]<<" \n"[i==n];
//	F(i,1,tot) cout<<cnt[i][0]<<' '<<cnt[i][1]<<'\n'; 
	int ans=0;
	F(i,1,n){
		F(j,0,1){
			if(cnt[bel1[i]][j]&&cnt[bel2[i]][j]){
				cnt[bel1[i]][j]--;
				cnt[bel2[i]][j]--;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<'\n';
}

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin.tie(0)->ios::sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--) run();
}
