#include <bits/stdc++.h> 
using namespace std;
#define fastIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N = 100003;
int T,n;
int p[N],q[N];
string s,t,a,b;
void Main(){
	cin >> n >> s >> t >> a >> b;  s=" "+s; t=" "+t;
	bool flagA=1;
	int numa=0,numb=0,ida,idb;
	for(int i=0;i<n;i++){
		if(a[i]=='0'){
			++numa; ida=i+1;
		}
		if(b[i]=='0'){
			++numb; idb=i+1;
		}
	}
	for(int i=2;i<=n;i++){
		if(s[i]!=s[i-1]){ flagA=0; break; }
	}
	if(flagA){ int ans=0;
		for(int i=1;i<=n;i++){
			if(t[i]==s[i]) ++ans;
		}
		cout << ans << endl;
		return;
	}
	if(a==b){ int cnt1=0,cnt2=0,len=0,ans=0;
		for(int i=1;i<=n;i++){
			if(a[i-1]=='1'){
				cnt1+=s[i]-'0'; cnt2+=t[i]-'0'; len++;
			}
			else{
				ans+=min(cnt1,cnt2); ans+=min(len-cnt1,len-cnt2);
				cnt1=cnt2=len=0; ans+=(s[i]==t[i]);
			}
		}
		ans+=min(cnt1,cnt2); ans+=min(len-cnt1,len-cnt2);
		cout << ans << endl;
		return;
	}
	if(numa==1&&numb==1){
		for(int i=1;i<=n;i++){
			p[i]=p[i-1]+s[i]-'0';
			q[i]=q[i-1]+t[i]-'0';
		}
		if(ida<idb){
			swap(ida,idb); swap(s,t); swap(a,b);
		}
		int ans=min(q[idb-1],p[ida-1])+min(idb-1-q[idb-1],ida-1-p[ida-1]);
		int numa=max(0,p[ida-1]-q[idb-1]); int numb=max(0,ida-1-p[ida-1]-idb+1+q[idb-1]);
		int numc=q[n]-q[idb]; int numd=n-idb-numc;
		if(t[idb]=='0'){
			if(numb){ numb--; ans++; }
		}
		else{
			if(numa){ numa--; ans++; }
		}
		ans+=min(numc,numa)+min(numb,numd);
		numc=max(0,numc-numa);
		numd=max(0,numd-numb);
		if(s[ida]=='0'){
			if(numd){ numd--; ans++; }
		}
		else if(numc){ numc--; ans++; }
		numa=p[n]-p[ida]; numb=n-ida-numa;
		ans+=min(numc,numa)+min(numb,numd);
		cout << ans << endl;
	}
}
signed main(){ freopen("edit.in","r",stdin); freopen("edit.out","w",stdout); fastIO;
	cin >> T;
	while(T--) Main();
	return 0;
}
