#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0;
	int c=getchar();
	bool f=0;
	while(c<48||c>57) f=(c=='-'),c=getchar();
	while(c>47&&c<58) x=(x<<3)+(x<<1)+(c&15),c=getchar();
	return f?-x:x;
}
inline void write(ll x,char end='\n'){
	if(x==0){
		putchar('0');
		putchar(end);
		return;
	}
	if(x<0) putchar('-'),x=-x;
	short ch[30]={0},cnt=0;
	while(x) ch[cnt++]=x%10,x/=10;
	while(cnt--) putchar(ch[cnt]^48);
	putchar(end);
}
const int N=2e5+5;
int n;
char s1[N],s2[N],t1[N],t2[N];
inline void solve(){
	n=read();
	scanf("%s%s%s%s",s1+1,s2+1,t1+1,t2+1);
	int sumone=0;
	int sumpair=0;
	s1[n+1]=s2[n+1]=t1[n+1]=t2[n+1]='0';
	for(int i=1;i<=n;++i) sumone+=(s1[i]=='1')+(s2[i]=='1');
	int nowsum1=0,nowsum2=0;
	int lst=0;
	for(int i=1,j=1,lstj=1;i<=n+1;++i){
		if(t1[i]=='0'){
			if(j>1&&j<=i){
				int needtodel=min(j-lst-2,min(nowsum2,nowsum1));
				if(needtodel<0) needtodel=0;
				sumpair+=needtodel;
				nowsum1-=needtodel;
				nowsum2=0;
				if(j>1&&j-1<i&&lst<j-1&&s2[j-1]=='1'&&nowsum1){
					nowsum1--;
					sumpair++;
				}
			}
			while(j<=i){
				lstj=j;
				while(j<=n+1&&t2[j]=='1'){
					nowsum2+=(s2[j]=='1');
					++j;
				}
				if(j<i){
					int needtodel=min(nowsum2,nowsum1);
					if(needtodel<0) needtodel=0;
					sumpair+=needtodel;
					nowsum1-=needtodel;
					nowsum2=0;
					if(nowsum1&&s2[j]=='1'){
						nowsum1--;
						sumpair++;
					}
				}
				++j;
			}
			if(j-1==i){
				int needtodel=min(nowsum2,nowsum1);
				if(needtodel<0) needtodel=0;
//				printf("last i=%d, i=%d, needtodel=%d\n",lst,i,needtodel);
				sumpair+=needtodel;
				nowsum2=0;
				nowsum1=0;
				if(s1[i]=='1'&&s2[j-1]=='1') ++sumpair;
				lst=i;lstj=j-1;
				continue;
			}
			int needtodel=min(i-lstj,min(nowsum2,nowsum1));
			if(needtodel<0) needtodel=0;
			sumpair+=needtodel;
			nowsum2-=needtodel;
			nowsum1=0;
			if(nowsum2&&s1[i]=='1'){
				nowsum2--;
				sumpair++;
			}
			lst=i;
		}
		else nowsum1+=(s1[i]=='1');
	}
	write(n-(sumone-sumpair*2));
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=read();
	while(T--) solve();
	return 0;
}
