#include<bits/stdc++.h>//¼ÇµÃÄÃÊÖ±í 
#define int long long
using namespace std;
int t,n,cnt1[200005],cnt2[200005],cnt3[200005],cnt4[200005],fr1[200005],fr2[200005];
string s1,s2,t1,t2;
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>s1>>s2>>t1>>t2;
		s1=" "+s1,s2=" "+s2,t1=" "+t1,t2=" "+t2;
		memset(cnt1,0,sizeof cnt1);
		memset(cnt2,0,sizeof cnt2);
		memset(cnt3,0,sizeof cnt3);
		memset(cnt4,0,sizeof cnt4);
		memset(fr1,0,sizeof fr1);
		memset(fr2,0,sizeof fr2);
		int cntx=0,cnty=0,ans=0;
		for(int i=1;i<=n;i++){
			if(t1[i]=='1'){
				if(t1[i]!=t1[i-1])cntx++;
				if(s1[i]=='1')cnt2[cntx]++;
				else cnt1[cntx]++;
				fr1[i]=cntx;
			}
		}
		for(int i=1;i<=n;i++){
			if(t2[i]=='1'){
				if(t2[i]!=t2[i-1])cnty++;
				if(s2[i]=='1')cnt4[cnty]++;
				else cnt3[cnty]++;
				fr2[i]=cnty;
			}
		}
		for(int i=1;i<=n;i++){
			if(!fr1[i]&&!fr2[i])ans+=s1[i]==s2[i];
			else if(fr1[i]&&!fr2[i]){
				if(s2[i]=='0'){
					if(cnt1[fr1[i]])cnt1[fr1[i]]--,ans++;
				}
				else{
					if(cnt2[fr1[i]])cnt2[fr1[i]]--,ans++;
				}
			}
			else if(!fr1[i]&&fr2[i]){
				if(s1[i]=='0'){
					if(cnt3[fr2[i]])cnt3[fr2[i]]--,ans++;
				}
				else{
					if(cnt4[fr2[i]])cnt4[fr2[i]]--,ans++;
				}
			}
		}
		for(int i=1;i<=n;i++)if(fr1[i]&&fr2[i]){
			if(cnt1[fr1[i]]&&cnt3[fr2[i]]){
				cnt1[fr1[i]]--,cnt3[fr2[i]]--,ans++;
				continue;
			}
			if(cnt2[fr1[i]]&&cnt4[fr2[i]]){
				cnt2[fr1[i]]--,cnt4[fr2[i]]--,ans++;
				continue;
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}
