#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll long long
#define db double
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=1e18+10;
const db eps=1e-6;
ll read() {
	ll o=0,w=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1;c=getchar();}
	while(c>='0'&&c<='9') {o=o*10+c-'0';c=getchar();}
	return o*w;
}
namespace dada {

const int N=1e5+10;
int n;
char s[2][N],v[2][N];
int Main() {
	scanf("%d%s%s%s%s",&n,s[0]+1,s[1]+1,v[0]+1,v[1]+1);
	int l=1,r[2]={0,0},cnt[2][2]={{0,0},{0,0}},ans=0;
	while(l<=n) {
		for(int o=0;o<2;o++) if(r[o]<l) {
			cnt[o][0]=cnt[o][1]=0;
			cnt[o][s[o][l]-'0']=1;
			r[o]=l;
			while(r[o]<n&&v[o][r[o]]=='1'&&v[o][r[o]+1]=='1') {
				r[o]++;
				cnt[o][s[o][r[o]]-'0']++;
			}
		}
		int p=(r[0]<r[1]?0:1);
		for(int i=0;i<2;i++) {
			int ck=min(cnt[p][i],cnt[p^1][i]);
			cnt[p][i]-=ck,cnt[p^1][i]-=ck;
			ans+=ck;
		}
		for(int i=0;i<2;i++) if(cnt[p][i]) {
			cnt[p^1][i^1]-=cnt[p][i],cnt[p][i]=0;
		}
		l=r[p]+1;
	}
	cout<<ans<<'\n';
	return 0;
}





}
int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=read();
	while(T--) {
		dada::Main();
	}
	return 0;
}
/*
cd edit
g++ edit.cpp -o edit -std=c++14 -Wall -O2
./edit
cp edit1.in edit.in
diff edit.out edit1.ans -w
*/