#include<bits/stdc++.h>

#define int long long
#define mem(x,y) memset(x,y,sizeof(x))
#define rep(i,l,r) for(int i = l;i <= r;i ++)
#define dep(i,l,r) for(int i = l;i >= r;i --)

using namespace std;

int read(){
	int s = 0,w = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')w = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9')s = s * 10 + ch - '0',ch = getchar();
	return s * w;
}

int t;
int n;
int a[1000010];
int b[1000010];
bool bk1[1000010];
bool bk2[1000010];
char s[1000010];
int ans;
int nowa,nowb;
int cnta[1000010][2],cntb[1000010][2];
int pos1[1000010],pos2[1000010];

void doita(int l,int r){
	if(l > r)return ;
	//cout<<"l = "<<l<<",r = "<<r<<endl;
	nowa ++;
	rep(i,l,r)cnta[nowa][a[i]] ++;
	rep(i,l,r)pos1[i] = nowa;
}

void doitb(int l,int r){
	if(l > r)return ;
//	cout<<"l = "<<l<<",r = "<<r<<endl;
	nowb ++;
	rep(i,l,r)cntb[nowb][b[i]] ++;
	rep(i,l,r)pos2[i] = nowb;
}

void solve(){
	n = read();
	scanf("%s",s + 1);rep(i,1,n)a[i] = s[i] - '0';
	scanf("%s",s + 1);rep(i,1,n)b[i] = s[i] - '0';
	scanf("%s",s + 1);rep(i,1,n)bk1[i] = s[i] - '0';
	scanf("%s",s + 1);rep(i,1,n)bk2[i] = s[i] - '0';
	rep(i,1,n)cnta[i][0] = cnta[i][1] = cntb[i][0] = cntb[i][1] = 0;
	ans = nowa = nowb = 0;
	rep(i,1,n)if(!bk1[i] && !bk2[i])ans += (a[i] == b[i]);
	int lst = 1;
	bk1[n + 1] = bk2[n + 1] = 0;
	rep(i,1,n + 1){
		if(bk1[i])continue;
		doita(lst,i - 1);
		lst = i + 1;
	}
	lst = 1;
	rep(i,1,n + 1){
		if(bk2[i])continue;
		doitb(lst,i - 1);
		lst = i + 1;
	}
	rep(i,1,n){
		if(bk1[i] && !bk2[i]){
			int pos = pos1[i];
			if(cnta[pos][b[i]]){
				ans ++;
				cnta[pos][b[i]] --;
			}
		}
	}
	rep(i,1,n){
		if(!bk1[i] && bk2[i]){
			int pos = pos2[i];
			if(cntb[pos][a[i]]){
				ans ++;
				cntb[pos][a[i]] --;
			}
		}
	}
	rep(i,1,n){
		if(bk1[i] && bk2[i]){
			int p1,p2;p1 = pos1[i],p2 = pos2[i];
			if(cnta[p1][0] && cntb[p2][0]){
				cnta[p1][0] --;
				cntb[p2][0] --;
				ans ++; 
			}
			else {
				if(cnta[p1][1] && cntb[p2][1]){
					cnta[p1][1] --;
					cntb[p2][1] --;
					ans ++;
				}
			}
		}
	}
	printf("%lld\n",ans);
}

signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>t;
	while(t --)solve();
}

/*

1
6
011101
111010
111010
101101

*/
