#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<numeric>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5+10;
const int N=1e5;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
int n,ans=0;
char a[MAXN],b[MAXN];
char s[MAXN],t[MAXN];
int suma[MAXN],sumb[MAXN];
priority_queue <int,vector<int>,greater<int>> A[2],B[2];
inline void solve(){
	scanf("%d",&n);
	scanf("%s%s",a+1,b+1);
	scanf("%s%s",s+1,t+1);
	for(int i=1;i<=n;i++)
	{
		a[i]^='0';
		b[i]^='0';
		s[i]^='0';
		t[i]^='0';
		A[a[i]].push(i);
		B[b[i]].push(i);
		suma[i]=suma[i-1]+!s[i];
		sumb[i]=sumb[i-1]+!t[i];
	}
	ans=0;
	for(int i=1;i<=n;i++)
	{
		A[a[i]].pop();
		B[b[i]].pop();
		if(s[i]&&t[i]){
			if(a[i]^b[i]&&!A[!a[i]].empty()){
				int x=A[!a[i]].top();
				if(suma[x]==suma[i]){
					A[!a[i]].pop();
					A[a[i]].push(x);
					swap(a[i],a[x]);
				}
			}
			if(a[i]^b[i]&&!B[!b[i]].empty()){
				int x=B[!b[i]].top();
				if(sumb[x]==sumb[i]){
					B[!b[i]].pop();
					B[b[i]].push(x);
					swap(b[i],b[x]);
				}
			}
		}
		else if(s[i]){
			if(a[i]^b[i]&&!A[!a[i]].empty()){
				int x=A[!a[i]].top();
				if(suma[x]==suma[i]){
					A[!a[i]].pop();
					A[a[i]].push(x);
					swap(a[i],a[x]);
				}
			}
		}
		else if(t[i]){
			if(a[i]^b[i]&&!B[!b[i]].empty()){
				int x=B[!b[i]].top();
				if(sumb[x]==sumb[i]){
					B[!b[i]].pop();
					B[b[i]].push(x);
					swap(b[i],b[x]);
				}
			}
		}
		ans+=(a[i]==b[i]);
	}
	printf("%d\n",ans);
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	#ifdef LOCAL
	atexit([](){fprintf(stderr,"%.3lfs\n",(double)clock()/CLOCKS_PER_SEC);});
	#endif
	int t;
	scanf("%d",&t);
	while(t--)
	{
		solve();
	}
	return 0;
}