#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,N=1e5+7;
ll n,ans,cnta[N],cntb[N];
char sa[N],sb[N],ta[N],tb[N];
void mian() {
	ans=0,memset(cnta,0,sizeof(cnta)),memset(cntb,0,sizeof(cntb));
	scanf("%lld%s%s%s%s",&n,sa+1,sb+1,ta+1,tb+1);
	for (ll l=1,r;l<=n;l=r+1) {
		if (ta[l]=='0'&&tb[l]=='0') ans+=sa[l]!=sb[l],r=l;
		else {
			for (r=l;r<n&&!(ta[r+1]=='0'&&tb[r+1]=='0');r++);
			for (ll x=l,y;x<=r;x=y+1) {
				if (ta[x]=='0') y=x;
				else {
					for (y=x;y<r&&ta[y+1]!='0';y++);
					for (ll i=x;i<=y;i++) cnta[x]+=sa[i]=='1';
					for (ll i=x;i<=y;i++) if (tb[i]=='0'&&sb[i]=='1') {
						if (!cnta[x]) ans++;
						else cnta[x]--;
					}
				}
			}
			for (ll x=l,y;x<=r;x=y+1) {
				if (tb[x]=='0') y=x;
				else {
					for (y=x;y<r&&tb[y+1]!='0';y++);
					for (ll i=x;i<=y;i++) cntb[x]+=sb[i]=='1';
					for (ll i=x;i<=y;i++) if (ta[i]=='0'&&sa[i]=='1') {
						if (!cntb[x]) ans++;
						else cntb[x]--;
					}
				}
			}
			ll ca=0,cb=0;
			for (ll i=l;i<=r;i++) {
				if (ta[i]=='0') ans+=ca,ca=0,cb+=cntb[i];
				else if (tb[i]=='0') ans+=cb,cb=0,ca+=cnta[i];
				else {
					ca+=cnta[i],cb+=cntb[i];
					if (ca&&cb) ca--,cb--;
				}
			}
			ans+=ca+cb;
		}
	}
	cout<<n-ans<<"\n";
}
bool ORY; int main() {
//	freopen("edit2.in","r",stdin);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
//	while (1)
	int t; for (scanf("%d",&t);t--;)
	mian();
	cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
	return 0; 
}
