#include <bits/stdc++.h>
using namespace std;

const int N=1e5+5;

int t,n;
int a[N],b[N],c[N],d[N];
int cnta[2],cntb[2];

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> t;
	while(t--){
		memset(cnta,0,sizeof(cnta));
		memset(cntb,0,sizeof(cntb));
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		memset(d,0,sizeof(d));
		cin >> n;
		string tmp;
		cin >> tmp;
		for(int i=0;i<tmp.length();i++){
			a[i]=tmp[i]-'0';
		}
		cin >> tmp;
		for(int i=0;i<tmp.length();i++){
			b[i]=tmp[i]-'0';
		}
		cin >> tmp;
		for(int i=0;i<tmp.length();i++){
			c[i]=tmp[i]-'0';
		}
		cin >> tmp;
		for(int i=0;i<tmp.length();i++){
			d[i]=tmp[i]-'0';
		}
		int pos0=0,pos1=0,ans=0;
		for(int i=0;i<n;i++){
			pos0=max(pos0,i);
			pos1=max(pos1,i);
			if(!c[i])memset(cnta,0,sizeof(cnta));
			if(!d[i])memset(cntb,0,sizeof(cntb));
			while(c[pos0])cnta[a[pos0]]++,pos0++;
			while(d[pos1])cntb[b[pos1]]++,pos1++;
			if(!c[i]&&!d[i])ans+=(a[i]==b[i]);
			if(c[i]&&!d[i]&&cnta[b[i]]>0){
				cnta[b[i]]--;
				ans++;
			}
			if(!c[i]&&d[i]&&cntb[a[i]]>0){
				cntb[a[i]]--;
				ans++;
			}
			if(c[i]&&d[i]){
				if(cnta[0]>0&&cntb[0]>0)ans++,cnta[0]--,cntb[0]--;
				if(cnta[1]>0&&cntb[1]>0)ans++,cnta[1]--,cntb[1]--;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
