#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int T,n,ans,S11,S10,S21,S20,FLAGA,FLAGB,FLAGC1,FLAGC2;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	string s1,s2,flag1,flag2;
	cin>>T;
	while(T--){
		ans=0,S11=0,S10=0,S21=0,S20=0;
		FLAGA=1,FLAGB=0,FLAGC1=0,FLAGC2=0;
		scanf("%d",&n);
		cin>>s1>>s2>>flag1>>flag2;
		for(int i=1;i<=n;i++){
			if(s1[i]==s1[i-1]) FLAGA++;
			if(flag1[i-1]==flag2[i-1]) FLAGB++;
			if(flag1[i-1]=='0') FLAGC1++;
			if(flag2[i-1]=='0') FLAGC2++;
			if(s1[i-1]=='1') S11++;
			if(s1[i-1]=='0') S10++;
			if(s2[i-1]=='1') S21++;
			if(s2[i-1]=='0') S20++;
		}
		if(FLAGB==n){
			for(int i=1;i<=n;i++){
				if(flag1[i-1]=='0'){
					if(s1[i-1]==s2[i-1]){
						ans++;
						if(s2[i-1]=='0') S11--,S21--;
						else S10--,S20--;
					}
					else{
						if(s2[i-1]=='0') S11--,S20--;
						else S10--,S21--;
					}
				}
			}
			ans=ans+min(S11,S21)+min(S10,S20);
			cout<<ans<<endl;
		}
		else if(FLAGA==n){
			if(s1[0]=='1') cout<<S21<<endl;
			else cout<<S20<<endl;
		}
		else if(FLAGC1==FLAGC2&&FLAGC1==1){
			ans=min(S11,S21)+min(S10,S20);
			cout<<ans<<endl;
		}
	}
	return 0;
}
