#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e5;
int n,m;
int a[2][N + 2],s[2][N + 2];
struct interval {
	int l,r,c;
} p[N * 2 + 2],q[N * 2 + 2];
int sum[N * 2 + 2][2];
int get01() {
	char c=getchar();
	while(c!='0'&&c!='1') c=getchar();
	return c=='1';
}
int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		for(int i=1; i<=n; ++i) a[0][i]=get01();
		for(int i=1; i<=n; ++i) a[1][i]=get01();
		for(int i=1; i<=n; ++i) s[0][i]=get01();
		for(int i=1; i<=n; ++i) s[1][i]=get01();
		int ans=0;
		for(int i=1; i<=n; ++i)
			if(!s[0][i]&&!s[1][i])
				ans+=(a[0][i]==a[1][i]);
		m=0;
		for(int i=1; i<=n; ++i) {
			if(!s[0][i]) continue;
			int j=i;
			while(j<n&&s[0][j+1]) ++j;
			p[++m]={i,j,0};
			i=j;
		}
		for(int i=1; i<=n; ++i) {
			if(!s[1][i]) continue;
			int j=i;
			while(j<n&&s[1][j+1]) ++j;
			p[++m]={i,j,1};
			i=j;
		}
		sort(p+1,p+m+1,[](auto x,auto y) {
			if(x.l!=y.l) return x.l<y.l;
			return x.r>y.r;
		});
		int cnt=m;
		m=0;
		for(int i=1,maxn=0; i<=cnt; ++i)
			if(p[i].r>maxn) {
				maxn=p[i].r;
				q[++m]=p[i];
			}
		for(int i=1; i<=m; ++i) {
			auto [l,r,c]=q[i];
			int x=l,y=r;
			if(i>1) x=max(x,q[i-1].r+1);
			if(i<m) y=min(y,q[i+1].l-1);
			sum[i][0]=count(a[c]+l,a[c]+r+1,0);
			sum[i][1]=count(a[c]+l,a[c]+r+1,1);
			for(int j=x; j<=y; ++j)
				if(sum[i][a[c^1][j]]) {
					--sum[i][a[c^1][j]];
					++ans;
				}
			if(i>1) {
				int both=max(0,q[i-1].r-q[i].l+1);
				for(int j=0; j<2; ++j) {
					int d=min({sum[i-1][j],sum[i][j],both});
					ans+=d;
					sum[i-1][j]-=d;
					sum[i][j]-=d;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}