#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int t;
int n;
int s[2][MAXN];
int l[2][MAXN];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		memset(s,0,sizeof(s));
		memset(l,0,sizeof(l));
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			char x;
			scanf(" %c",&x);
			s[0][i]=s[0][i-1]+x-'0';
		}
		for(int i=1;i<=n;i++){
			char x;
			scanf(" %c",&x);
			s[1][i]=s[1][i-1]+x-'0';
		}
		int tmp=0;
		for(int i=1;i<=n;i++){
			char x;
			scanf(" %c",&x);
			l[0][i]=l[0][i-1];
			if(x=='0'||!tmp){
				l[0][i]=i;
			}
			tmp=x-'0';
		}
		tmp=0;
		for(int i=1;i<=n;i++){
			char x;
			scanf(" %c",&x);
			l[1][i]=l[1][i-1];
			if(x=='0'||!tmp){
				l[1][i]=i;
			}
			tmp=x-'0';
		}
		int now1=n,now2=n;
		int tmp1,tmp2,tmp3,tmp4;
		int ans=0;
		tmp1=s[1][now2]-s[1][l[1][now2]-1];
		tmp2=now2-l[1][now2]+1-tmp1;
		tmp3=s[0][now1]-s[0][l[0][now1]-1];
		tmp4=now1-l[0][now1]+1-tmp3;
		while(now1&&now2){
			swap(tmp1,tmp3);
			swap(tmp2,tmp4);
			while(l[1][now2]>=l[0][now1]){
				if(tmp1>=tmp3){
					ans+=tmp3;
					tmp1-=tmp3;
				}
				else{
					ans+=tmp1;
					tmp2-=tmp3-tmp1;
					tmp3-=tmp1;
					//printf("%d %d\n",now2,tmp2);
					tmp1=0;
				}
				if(tmp2>=tmp4){
					ans+=tmp4;
					tmp2-=tmp4;
				}
				else{
					ans+=tmp2;
					tmp1-=tmp4-tmp2;
					tmp4-=tmp2;
					//printf("%d %d\n",now2,tmp1);
					tmp2=0;
				}
				now2=l[1][now2]-1;
				tmp3=s[1][now2]-s[1][l[1][now2]-1];
				tmp4=now2-l[1][now2]+1-tmp3;
			}
			if(!now1||!now2){
				break;
			}
			swap(tmp1,tmp3);
			swap(tmp2,tmp4);
			while(l[0][now1]>=l[1][now2]){
				if(tmp1>=tmp3){
					ans+=tmp3;
					tmp1-=tmp3;
				}
				else{
					ans+=tmp1;
					tmp2-=tmp3-tmp1;
					//printf("%d %d\n",now1,tmp2);
					tmp1=0;
				}
				if(tmp2>=tmp4){
					ans+=tmp4;
					tmp2-=tmp4;
				}
				else{
					ans+=tmp2;
					tmp1-=tmp4-tmp2;
					//printf("%d %d\n",now1,tmp1);
					tmp2=0;
				}
				now1=l[0][now1]-1;
				tmp3=s[0][now1]-s[0][l[0][now1]-1];
				tmp4=now1-l[0][now1]+1-tmp3;
			}
		}
		printf("%d\n",ans);
	}
}
