#include<bits/stdc++.h>
#define ll long long
using namespace std;

inline ll read() {
	ll res=0,f=0;
	char c;
	do {
		c=getchar();
		f|=c=='-';
	} while(!isdigit(c));
	do {
		res=(res<<1)+(res<<3)+(c^48);
		c=getchar();
	} while(isdigit(c));
	return f?-res:res;
}

void write(ll x) {
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}

const ll N=1e6+10;

ll T,len,ans,s1_num1,s2_num1,s1_num0,s2_num0,flag_B,flag1_num0,flag2_num0;

char s1[N],s2[N],flag1[N],flag2[N];

inline void init() {
	s1_num1=0,s2_num1=0,s1_num0=0,s2_num0=0,ans=0;
	flag1_num0=0,flag2_num0=0;
	flag_B=false;
}

inline void work1() {

}

inline void workA() {
	ans=(s1_num1==len)?s2_num1:s2_num0;
	write(ans);
	putchar('\n');
}

inline void workB() {
	ll num1=0,num2=0,l=0;
	for(ll i=0; i<len; i++) {
		if(flag1[i]=='0') {
			ans+=(s1[i]==s2[i]);
			ans+=min(num1,num2)+i-l-1-max(num1,num2);
			l=i;
			num1=0,num2=0;
		} else {
			num1+=s1[i]-'0';
			num2+=s2[i]-'0';
		}
	}
	ans+=min(num1,num2)+len-l-max(num1,num2);
	write(ans);
	putchar('\n');
}

inline void workC() {
	ll num1=-1,num2=-1,s1_num[2][2],s2_num[2][2];
	for(ll i=0; i<len; ++i) {
		if(flag1[i]=='0') num1=i;
		if(flag2[i]=='0') num2=i;
		if(num1==-1) {
			s1_num[0][1]+=s1[i]-'0';
			s1_num[0][0]+=(s1[i]=='0');
		} else {
			s1_num[1][1]+=s1[i]-'0';
			s1_num[1][0]+=(s1[i]=='0');
		}
		if(num2==-1) {
			s2_num[0][1]+=s2[i]-'0';
			s2_num[0][0]+=(s2[i]=='0');
		} else {
			s2_num[1][1]+=s2[i]-'0';
			s2_num[1][0]+=(s2[i]=='0');
		}
	}
	ll minn=min(num1,num2),maxn=max(num1,num2);
	minn=min(s1_num[0][1],s2_num[0][1]);
	s1_num[0][1]-=minn;
	s2_num[0][1]-=minn;
	ans+=minn;
	minn=min(s1_num[0][0],s2_num[0][0]);
	s1_num[0][0]-=minn;
	s2_num[0][0]-=minn;
	ans+=minn;
	minn=min(s1_num[1][1],s2_num[1][1]);
	s1_num[1][1]-=minn;
	s2_num[1][1]-=minn;
	ans+=minn;
	minn=min(s1_num[1][0],s2_num[1][0]);
	s1_num[1][0]-=minn;
	s2_num[1][0]-=minn;
	ans+=minn;
	ans+=min(s2_num[0][1],s1_num[1][1])+num2-num1-1-max(s2_num[0][1],s1_num[1][1]);
	if(num1<num2)
		ans+=min(s2_num[0][1],s1_num[1][1])+num2-num1-1-max(s2_num[0][1],s1_num[1][1]);
	else
		ans+=min(s2_num[1][1],s1_num[0][1])+num1-num2-1-max(s2_num[1][1],s1_num[0][1]);

}

inline void work() {
	T=read();
	while(T--) {
		init();
		len=read();
		char ch;
		for(ll i=0; i<len; i++) {
			s1[i]=getchar();
		}
		ch=getchar();
		for(ll i=0; i<len; i++) {
			s2[i]=getchar();
		}
		ch=getchar();
		for(ll i=0; i<len; i++) {
			flag1[i]=getchar();
		}
		ch=getchar();
		for(ll i=0; i<len; i++) {
			flag2[i]=getchar();
		}
		ch=getchar();
		if(len<=10) {
			work1();
			continue;
		}
		for(ll i=0; i<len; i++) {
			s1_num1+=(s1[i]-'0');
			s1_num0+=(s1[i]=='0');
			s2_num1+=(s2[i]-'0');
			s2_num0+=(s2[i]=='0');
			if(flag1[i]!=flag2[i]) flag_B=true;
			flag1_num0+=(flag1[i]=='0');
			flag2_num0+=(flag2[i]=='0');
		}
		if(s1_num1==len||s1_num0==len) {
			workA();
			continue;
		}
		if(!flag_B) {
			workB();
			continue;
		}
		if(flag1_num0==1&&flag2_num0==1) {
			workC();
			continue;
		}
	}
}

int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	work();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
