#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
inline int read(){
	int res=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch))
		flag=(ch=='-')?-1:1,
		ch=getchar();
	while(isdigit(ch))
		res=(res<<3)+(res<<1)+(ch^48),
		ch=getchar();
	return res*flag;
}
template<typename T>
inline void write(T x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
int n,ans;
int bel1[N],one1[N],zero1[N],L1[N],R1[N],cnt1;
int bel2[N],one2[N],zero2[N],L2[N],R2[N],cnt2;
char st1[N],st2[N],tl1[N],tl2[N];
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	for(int T=read();T;T--){
		n=read(),cnt1=0,cnt2=0,ans=0;
		memset(one1,0,sizeof one1);
		memset(one2,0,sizeof one2);
		memset(zero1,0,sizeof zero1);
		memset(zero2,0,sizeof zero2);
		scanf("%s",st1+1);
		scanf("%s",st2+1);
		scanf("%s",tl1+1);
		scanf("%s",tl2+1);
		for(int l=1,r=0;l<=n;){
			++cnt1;
			if(tl1[l]=='0'){
				r=l;
				bel1[r]=cnt1;
				if(st1[r]=='1') ++one1[cnt1];
				else ++zero1[cnt1];
			}
			else{
				while(r<n and tl1[r+1]=='1'){
					++r,bel1[r]=cnt1;
					if(st1[r]=='1') ++one1[cnt1];
					else ++zero1[cnt1];
				}				
			}
			L1[cnt1]=l,R1[cnt1]=r;
			l=r+1;
		}
		for(int l=1,r=0;l<=n;){
			++cnt2;
			if(tl2[l]=='0'){
				r=l;
				bel2[r]=cnt1;
				if(st2[r]=='1') ++one2[cnt2];
				else ++zero2[cnt2];
			}
			else{
				while(r<n and tl2[r+1]=='1'){
					++r,bel2[r]=cnt2;
					if(st2[r]=='1') ++one2[cnt2];
					else ++zero2[cnt2];
				}				
			}
			L2[cnt2]=l,R2[cnt2]=r;
			l=r+1;
		}
		for(int up=1,down=1;up<=cnt1 and down<=cnt2;){
//			printf("%d %d\n",up,down);
//			for(int i=1;i<=cnt1;i++){
//				printf("%d %d %d %d\n",L1[i],R1[i],one1[i],zero1[i]);
//			}
//			for(int i=1;i<=cnt2;i++){
//				printf("%d %d %d %d\n",L2[i],R2[i],one2[i],zero2[i]);
//			}
			int &o1=one1[up],&z1=zero1[up],
				&o2=one2[down],&z2=zero2[down];
			ans+=min(o1,o2)+min(z1,z2); 
			if(o1>=o2) o1-=o2,o2=0;
			else o2-=o1,o1=0;
			if(z1>=z2) z1-=z2,z2=0;
			else z2-=z1,z1=0;
			if(R1[up]>R2[down]){
				++down;
				if(o2 or z2){
					if(o1) o1-=o2+z2;
					else z1-=o2+z2; 					
				}
			}
			else{
				++up;
				if(o1 or z1){
					if(o2) o2-=o1+z1;
					else z2-=o1+z1; 					
				}
			}
		}
		write(ans),putchar('\n');
	}
	return 0;
}
