#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
	int x=0,t=0;
	char c=getchar();
	while(c<'0'||c>'9') t|=c=='-',c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return t?-x:x;
}
inline void putc(char c){
	putchar(c);
}
inline void write(int x){
	if(x<0) putc('-'),x=-x;
	if(x>9) write(x/10);
	putc('0'+x%10);
}
inline char getc(){
	char c=getchar();
	while(c<'0'||c>'1') c=getchar();
	return c;
}
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=1e5+10;
int n,s[2][N],t[2][N];
struct node{
	int l,r,c0,c1;
	node(int a=0,int b=0,int c=0,int d=0){ l=a,r=b,c0=c,c1=d; }
};
int main(){
//	system("fc edit1.out edit1.ans /n");
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=read();
	while(T--){
		n=read();
		for(int i=0;i<2;i++)
			for(int j=1;j<=n;j++)
				s[i][j]=getc()-'0';
		for(int i=0;i<2;i++)
			for(int j=1;j<=n;j++)
				t[i][j]=getc()-'0';
		vector<node>a,b;
		for(int i=1;i<=n;i++){
			if(!t[0][i]){ a.push_back(node(i,i,s[0][i]==0,s[0][i]==1));continue; }
			int j=i,c0=s[0][i]==0,c1=s[0][i]==1;
			while(j+1<=n&&t[0][j+1]==1) j++,c0+=s[0][j]==0,c1+=s[0][j]==1;
			a.push_back(node(i,j,c0,c1));
			i=j;
		}
		for(int i=1;i<=n;i++){
			if(!t[1][i]){ b.push_back(node(i,i,s[1][i]==0,s[1][i]==1));continue; }
			int j=i,c0=s[1][i]==0,c1=s[1][i]==1;
			while(j+1<=n&&t[1][j+1]==1) j++,c0+=s[1][j]==0,c1+=s[1][j]==1;
			b.push_back(node(i,j,c0,c1));
			i=j;
		}
		int p0=0,p1=0,ans=0;
		node cura=a[0],curb=b[0];
		while(p0<a.size()||p1<b.size()){
			if(cura.r<curb.r){
				int c0=min(cura.c0,curb.c0),c1=min(cura.c1,curb.c1);
				ans+=c0+c1;
				cura.c0-=c0,cura.c1-=c1;
				curb.c0-=c0,curb.c1-=c1;
				if(cura.c0) curb.c1-=cura.c0;
				if(cura.c1) curb.c0-=cura.c1;
				cura=a[++p0];
			}else if(cura.r>curb.r){
				int c0=min(cura.c0,curb.c0),c1=min(cura.c1,curb.c1);
				ans+=c0+c1;
				cura.c0-=c0,cura.c1-=c1;
				curb.c0-=c0,curb.c1-=c1;
				if(curb.c0) cura.c1-=curb.c0;
				if(curb.c1) cura.c0-=curb.c1;
				curb=b[++p1];
			}else{
				int c0=min(cura.c0,curb.c0),c1=min(cura.c1,curb.c1);
				ans+=c0+c1;
				if(cura.r==n) break;
				cura=a[++p0],curb=b[++p1];
			}
		}
		write(ans),putc('\n');
	}
}
