#include<bits/stdc++.h>
#define ll long long

using namespace std;
typedef pair<int,int> pii;
const int N=1e5+10;
int n,a[N],b[N],as[N],bs[N];
int sufa[N],sufb[N];
int suma[N][2],sumb[N][2];

void solve() {
	cin >> n;
	for(int i=1;i<=n;i++) {char c;cin>>c;a[i]=c-'0';}
	for(int i=1;i<=n;i++) {char c;cin>>c;b[i]=c-'0';}
	for(int i=1;i<=n;i++) {char c;cin>>c;as[i]=c-'0';}
	for(int i=1;i<=n;i++) {char c;cin>>c;bs[i]=c-'0';}
	for(int i=1;i<=n;i++) sufa[i]=sufb[i]=0;
	sufa[n+1]=n+1,sufb[n+1]=n+1;
	for(int i=1;i<=n;i++) if(as[i]==false) sufa[i]=i;
	for(int i=1;i<=n;i++) if(bs[i]==false) sufb[i]=i;
	for(int i=n;i>=1;i--) if(sufa[i]==0) sufa[i]=sufa[i+1];
	for(int i=n;i>=1;i--) if(sufb[i]==0) sufb[i]=sufb[i+1]; 
	int ida0=1,ida1=1,idb0=1,idb1=1;
	while(ida0<=n&&a[ida0]!=0) ida0++;
	while(idb0<=n&&b[idb0]!=0) idb0++;
	while(ida1<=n&&a[ida1]!=1) ida1++;
	while(idb1<=n&&b[idb1]!=1) idb1++;
	for(int i=1;i<=n;i++) {
		if(a[i]==b[i]) continue;
		if((as[i]==false)&&(bs[i]==false)) continue;
		bool flg=false;
		ida0=max(ida0,i);ida1=max(ida1,i);
		idb0=max(idb0,i);idb1=max(idb1,i);
		while(ida0<=n&&a[ida0]!=0) ida0++;
		while(idb0<=n&&b[idb0]!=0) idb0++;
		while(ida1<=n&&a[ida1]!=1) ida1++;
		while(idb1<=n&&b[idb1]!=1) idb1++;
		if(bs[i]==1) {
			if(a[i]==0&&b[i]==1) {
				if(idb0<sufb[i]&&idb0<=n) {
					swap(b[idb0],b[i]);
					idb1=min(idb1,idb0);
					while(idb0<=n&&b[idb0]!=0) idb0++;
					flg=true;
				}
			} else if(a[i]==1&&b[i]==0) {
				if(idb1<sufb[i]&&idb1<=n) {
					swap(b[idb1],b[i]);
					idb0=min(idb0,idb1);
					while(idb1<=n&&b[idb1]!=1) idb1++;
					flg=true;
				}
			}
		}
		if(a[i]==b[i]) continue;
		if((flg==false)&&(as[i]==1)) {
			if(b[i]==0&&a[i]==1) {
				if(ida0<sufa[i]&&ida0<=n) {
					swap(a[ida0],a[i]);
					ida1=min(ida1,ida0);
					while(ida0<=n&&a[ida0]!=0) ida0++;
				}
			} else if(b[i]==1&&a[i]==0) {
				if(ida1<sufa[i]&&ida1<=n) {
					swap(a[ida1],a[i]);
					ida0=min(ida0,ida1);
					while(ida1<=n&&a[ida1]!=1) ida1++;
				}
			}
		}
	} 
	int ans=0;
	for(int i=1;i<=n;i++)
		if(a[i]==b[i]) ans++;
	cout<<ans<<"\n";
	return ;
}

int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc;cin>>tc;
	while(tc--)solve();
	return 0;
}
