#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int T,n,ct1,ct2,ans;
char ssx[N],ssy[N],ttx[N],tty[N];
struct node{int r,c[2];}a[N],b[N];
int main(){
	freopen("edit.in" ,"r",stdin );
	freopen("edit.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		ct1=1,ct2=1;ans=0;
		memset(a,0,sizeof a);
		
		scanf("%d\n%s\n%s\n%s\n%s",&n,ssx,ssy,ttx,tty);
		
		ssx[n]='0';ssy[n]='0';ttx[n]='0';tty[n]='0';
		for (int i=0;i<=n;i++){
			if(ttx[i]=='0')a[ct1].r=i,ct1++;
			else a[ct1].c[ssx[i]-'0']++;
			if(tty[i]=='0')b[ct2].r=i,ct2++;
			else b[ct2].c[ssy[i]-'0']++;
		}
		
		int i=1,j=1;
		while(i<ct1&&j<ct2){
			while(a[i].r<b[j].r&&i<ct1){
				a[i].c[ssx[a[i].r]-'0']++;
				ans+=min(a[i].c[0],b[j].c[0])+min(a[i].c[1],b[j].c[1]);
				b[j].c[0]=max(0,b[j].c[0]-a[i].c[0]);b[j].c[1]=max(0,b[j].c[1]-a[i].c[1]);
				a[i].c[0]=0;a[i].c[1]=0;
				i++;
		 	}
			while(a[i].r==b[j].r&&i<ct1&&j<ct2){
				ans+=min(a[i].c[0],b[j].c[0])+min(a[i].c[1],b[j].c[1])+(ssx[a[i].r]==ssy[b[j].r]);
				a[i].c[0]=0;a[i].c[1]=0;b[j].c[0]=0;b[j].c[1]=0;
				i++;j++;
			}
			while(a[i].r>b[j].r&&j<ct2){
				b[j].c[ssy[b[j].r]-'0']++;
				ans+=min(a[i].c[0],b[j].c[0])+min(a[i].c[1],b[j].c[1]);
				a[i].c[0]=max(0,a[i].c[0]-b[j].c[0]);a[i].c[1]=max(0,a[i].c[1]-b[j].c[1]);
				b[j].c[0]=0;b[j].c[1]=0;
				j++;
			}	
			while(a[i].r==b[j].r&&i<ct1&&j<ct2){
				ans+=min(a[i].c[0],b[j].c[0])+min(a[i].c[1],b[j].c[1])+(ssx[a[i].r]==ssy[b[j].r]);
				a[i].c[0]=0;a[i].c[1]=0;b[j].c[0]=0;b[j].c[1]=0;
				i++;j++;
			}
		}
		printf("%d\n",ans-1);
	}
}
/*
压缩包：Forget#2501
PDf：memory@2107

T1调不动 看来只有 100  

fropen("","",in);
fropen("","",in);


GD-0335
I'm xiaoshui(yes), i'm a 蒟蒻。
Because I will AFO,i will write an articlue about this ,wait for you to look.
Can you celebrate me. Or you can play with me.
I hope thar I can forget OI before,but now sometimes I am happy to learn OI.
I enctoured many friends by OI.
It's memoriable for me toyour years.
Gooodbye OI.See you next life.

我英语不太好，将就看看
题外话 冬日绘版支持一下小帅计划 

luogu:544383 tzjahinie
	O:228942055
 崩铁：115821736
   零：19635543(?)
*/
