#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define ld long double
using namespace std;
const int N=1e5+10;
struct node{
	int l,r,x,y;
}qx[N],qy[N];
int n,c[N],d[N],cx,cy;
char a[N],b[N];
inline void init(){
	for(int i=1;i<=100000;i++) qx[i].l=qx[i].r=qx[i].x=qx[i].y=qy[i].l=qy[i].r=qy[i].x=qy[i].y=0;
	int l,x=0,y=0;
	for(int i=1;i<=n;i++){
		if(c[i]&&(!c[i-1])&&(!c[i+1])) c[i]=0;
		if(!c[i]) continue;
		if(a[i]=='0') x++;
		else y++;
		if(c[i]&&(!c[i-1])) l=i;
		if(c[i]&&(!c[i+1])) qx[++cx]={l,i,x,y},x=y=0;
	}
	x=y=0;
	for(int i=1;i<=n;i++){
		if(d[i]&&(!d[i-1])&&(!d[i+1])) d[i]=0;
		if(!d[i]) continue;
		if(b[i]=='0') x++;
		else y++;
		if(d[i]&&(!d[i-1])) l=i;
		if(d[i]&&(!d[i+1])) qy[++cy]={l,i,x,y},x=y=0;
	}
//	for(int i=1;i<=cx;i++) cout<<qx[i].l<<' '<<qx[i].r<<' '<<qx[i].x<<' '<<qx[i].y<<endl;
//	for(int i=1;i<=cy;i++) cout<<qy[i].l<<' '<<qy[i].r<<' '<<qy[i].x<<' '<<qy[i].y<<endl;
}
inline void tx(){
	int p=1,q=1,ans=0;
	for(int i=1;i<=n;i++){
		if((!c[i])&&(!d[i])){
			if(a[i]==b[i]) ans++;
			continue;
		}
		while(p<=cx&&qx[p].r<i) p++;
		while(q<=cy&&qy[q].r<i) q++;
		int x=0,y=0;
		if(qx[p].l<=i&&i<=qx[p].r) x=1;
		if(qy[q].l<=i&&i<=qy[q].r) y=1;
		if(x&&y){
			continue;
		}else if(x){
			if(b[i]=='0'&&qx[p].x) qx[p].x--,ans++;
			if(b[i]=='1'&&qx[p].y) qx[p].y--,ans++;
		}else if(y){
			if(a[i]=='0'&&qy[q].x) qy[q].x--,ans++;
			if(a[i]=='1'&&qy[q].y) qy[q].y--,ans++;
		}
	}
	p=1,q=1;
	for(int i=1;i<=n;i++){
		while(p<=cx&&qx[p].r<i) p++;
		while(q<=cy&&qy[q].r<i) q++;
		int x=0,y=0;
		if(qx[p].l<=i&&i<=qx[p].r) x=1;
		if(qy[q].l<=i&&i<=qy[q].r) y=1;
		if(x&&y){
			if(qx[p].x&&qy[q].x) qx[p].x--,qy[q].x--,ans++;
			else if(qx[p].y&&qy[q].y) qx[p].y--,qy[q].y--,ans++;
		}
	}
	cout<<ans<<endl;
}
inline void solve(){
	memset(c,0,sizeof(c));
	memset(d,0,sizeof(d));
	cx=cy=0;
	cin>>n>>a+1>>b+1;
	for(int i=1;i<=n;i++){
		char x;
		cin>>x;
		if(x=='1') c[i]=1;
		else c[i]=0; 
	}
	for(int i=1;i<=n;i++){
		char x;
		cin>>x;
		if(x=='1') d[i]=1;
		else d[i]=0; 
	}
	init(); 
	tx();
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}
