#include<iostream>
#define int long long
using namespace std;
const int N=1e5+5;
int n,a[N],b[N],t,cnta=1,cntb=1,pa[N],pb[N],sum;
char x[N];
signed main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%lld",&t);
	//t=2;
	while(t--){
		cnta=1,cntb=1;
		scanf("%lld",&n);
		scanf("%s",x+1);
		for(int i=1;i<=n;i++) {
			if(x[i]=='1') a[i]=1;
			else a[i]=0;
		}
		scanf("%s",x+1);
		for(int i=1;i<=n;i++) {
			if(x[i]=='1') b[i]=1;
			else b[i]=0;
		}
		scanf("%s",x+1);
		for(int i=1;i<=n;i++){
			//if(t==0) cout<<x[i];
			if(!(x[i]-'0')) pa[cnta++]=i;
		}
		scanf("%s",x+1);
		for(int i=1;i<=n;i++){
			if(!(x[i]-'0')) pb[cntb++]=i;
		}
		//if(t==0) cout<<endl;
		a[n+1]=0;
		b[n+1]=1;
		pa[cnta]=n+1;
		pb[cntb]=n+1;
		int i=1,j=1,suma1=0,sumb1=0,suma0=0,sumb0=0;
		for(int k=1;k<pa[1];k++) if(a[k]) suma1++; else suma0++;
		for(int k=1;k<pb[1];k++) if(b[k]) sumb1++; else sumb0++;
		while(!(i==cnta && j==cntb)){
			//if(t==0) cout<<pa[i]<<' '<<pb[j]<<' '<<suma1<<" "<<sumb1<<' '<<suma0<<" "<<sumb0<<endl;
			int s1=min(suma1,sumb1),s2=min(suma0,sumb0);
			sum+=s1+s2;
			//if(t==0) cout<<sum<<"\n";
			suma1-=s1;
			suma0-=s2;
			sumb1-=s1;
			sumb0-=s2;
			//if(t==0) cout<<pa[i]<<' '<<pb[j]<<' '<<suma1<<" "<<sumb1<<' '<<suma0<<" "<<sumb0<<endl;
			if(pa[i]<pb[j]){
				if(suma1) sumb0-=suma1,suma1=0;
				if(suma0) sumb1-=suma0,suma0=0;
				if(a[pa[i]]){
					if(sumb1) sum++,sumb1--;
					else sumb0--;
				} 
				else {
					if(sumb0) sum++,sumb0--;
					else sumb1--;
				}
				i++;
				for(int k=pa[i-1]+1;k<pa[i];k++) if(a[k]) suma1++; else suma0++;
			}
			else if(pa[i]>pb[j]){
				if(sumb1) suma0-=sumb1,sumb1=0;
				if(sumb0) suma1-=sumb0,sumb0=0;
				if(b[pb[j]]){
					if(suma1) sum++,suma1--;
					else suma0--;
				}
				else {
					if(suma0) sum++,suma0--;
					else suma1--;
				}
				j++;
				for(int k=pb[j-1]+1;k<pb[j];k++) if(b[k]) sumb1++; else sumb0++;
			}
			else {
				if(sumb1) suma0-=sumb1,sumb1=0;
				if(sumb0) suma1-=sumb0,sumb0=0;
				if(b[pb[j]]==a[pa[i]]) sum++;
				j++,i++;
				for(int k=pa[i-1]+1;k<pa[i];k++) if(a[k]) suma1++; else suma0++;
				for(int k=pb[j-1]+1;k<pb[j];k++) if(b[k]) sumb1++; else sumb0++;
			}
		}
		printf("%lld\n",sum);
		sum=0;
	}
	return 0;
}

