#include<bits/stdc++.h>
using namespace std;
namespace sub {
	const int N=1e5+66;
	int a[N],b[N],ta[N],tb[N];
	int n;
	void clr()
	{
		for(int i=1;i<=n;i++) a[i]=b[i]=ta[i]=tb[i]=0;
	}
	char ch;
	void mainn() {
		
		scanf("%d",&n);
		clr();
		for(int i=1; i<=n; i++) {
			cin>>ch;
			a[i]=ch-'0';
		}
		for(int i=1; i<=n; i++) {
			cin>>ch;
			b[i]=ch-'0';
		}
		for(int i=1; i<=n; i++) {
			cin>>ch;
			ta[i]=ch-'0';
			ta[i]^=1;
		}
		for(int i=1; i<=n; i++) {
			cin>>ch;
			tb[i]=ch-'0';
			tb[i]^=1;
		}
	//	pr();
		int wa0=0,wa1=0,wb0=0,wb1=0,ans=0;
		for(int j=1; j<=n&&!ta[j]; j++) {
			if(a[j]==1) wa1++;
			else wa0++;
		}
		for(int j=1; j<=n&&!tb[j]; j++) {
			if(b[j]==1) wb1++;
			else wb0++;
		}
		
		for(int i=1; i<=n; i++) {
			if(ta[i]&&tb[i]) {
				ans+=(a[i]==b[i]);
				for(int j=i+1; j<=n&&!ta[j]; j++) {
					if(a[j]==1) wa1++;
					else wa0++;
				}
				for(int j=i+1; j<=n&&!tb[j]; j++) {
					if(b[j]==1) wb1++;
					else wb0++;
				}
			} else if(ta[i]) {
				if(a[i]==1) {
					if(wb1) ans++,wb1--;
					else wb0--;
				} else {
					if(wb0) ans++,wb0--;
					else wb1--;
				}
				for(int j=i+1; j<=n&&!ta[j]; j++) {
					if(a[j]==1) wa1++;
					else wa0++;
				}
			} else if(tb[i]) {
				if(b[i]==1) {
					if(wa1) ans++,wa1--;
					else wa0--;
				} else {
					if(wa0) ans++,wa0--;
					else wa1--;
				}
				for(int j=i+1; j<=n&&!tb[j]; j++) {
					if(b[j]==1) wb1++;
					else wb0++;
				}
			} else {
				if(wa0&&wb0) {
					ans++;
					wa0--,wb0--;
				} else if(wa1&&wb1) {
					ans++;
					wa1--,wb1--;
				} else {
					if(wa0) wa0--;
					else wa1--;
					if(wb0) wb0--;
					else wb1--;
				}
			}
		}
		printf("%d\n",ans);
	}
}
int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--) {
		sub::mainn();
	}
	return 0;
}

