#include<bits/stdc++.h>
#define int long long

using namespace std;

int read(){
	int x;
	scanf("%lld",&x);
	return x;
}

void write(int x){
	printf("%lld",x);
} 

const int maxn=100005;
const int inf=1e18;

int n;
char s[maxn],s1[maxn],bk[maxn],bk1[maxn];
int lst[maxn],sum[maxn],sum1[maxn],bkk[maxn];

int c[maxn],c1[maxn];
int anss=0;

bool check(){
	int cnt=0;
		for(int i=1;i<=n;i++){
			cnt+=c[i];
		}
		if(cnt!=sum[n]){
			// cout<<cnt<<" "<<sum[n]<<endl;
			// cout<<11<<endl;
			return 0;
		}
		cnt=0;
		for(int i=1;i<=n;i++){
			cnt+=c1[i];
		}
		if(cnt!=sum1[n]){
			// cout<<22<<endl;
			return 0;
		}
		cnt=0;
		int lst=0;
		for(int i=1;i<=n;i++){
			cnt+=c[i];
			if(bk[i]=='0'){
				// cout<<cnt<<endl;
				if(cnt!=sum[i]-sum[lst]){
					// cout<<33<<endl;
					return 0;
				}
				lst=i;
				cnt=0;
			}
		}
		cnt=0;
		lst=0;
		for(int i=1;i<=n;i++){
			cnt+=c1[i];
			if(bk1[i]=='0'){
				if(cnt!=sum1[i]-sum1[lst]){
					// cout<<44<<endl;
					return 0;
				}
				lst=i;
				cnt=0;
			}
		}
		for(int i=1;i<=n;i++){
			if(bk[i]=='0'){
				if(c[i]!=s[i]-'0'){
					// cout<<55<<endl;
					return 0;
				}
			}
			if(bk1[i]=='0'){
				if(c1[i]!=s1[i]-'0'){
					// cout<<66<<endl;
					return 0;
				}
			}
		}
		return 1;
}

void dfs1(int dep){
	if(dep>n){
		if(!check()){
			return ;
		}
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(c[i]==c1[i]){
				cnt++;
			}
		}
		anss=max(anss,cnt);
		return ;
	}
	for(int i=0;i<=1;i++){
		c1[dep]=i;
		dfs1(dep+1);
		c1[dep]=0;
	}
}

void dfs(int dep){
	if(dep>n){
		dfs1(1);
		return ;
	}
	for(int i=0;i<=1;i++){
		c[dep]=i;
		dfs(dep+1);
		c[dep]=0;
	}
}

namespace sub1{
	bool check(){
		int c=s[1]-'0';
		for(int i=1;i<=n;i++){
			if(s[i]-'0'!=c){
				return 0;
			}
		}
		return 1;
	}
	void solve(){
		int cnt=0;
		if(s[1]=='1'){
			for(int i=1;i<=n;i++){
				if(s1[i]=='1'){
					cnt++;
				}
			}
		}
		else{
			for(int i=1;i<=n;i++){
				if(s1[i]=='0'){
					cnt++;
				}
			}
		}
		write(cnt);
		puts("");
	}
}

namespace sub2{
	bool check(){
		for(int i=1;i<=n;i++){
			if(bk[i]!=bk1[i]){
				return 0;
			}
		}
		return 1;
	}
	void solve(){
		int cnt=0;
		int lst=0;
		int flag=0;
		for(int i=1;i<=n;i++){
			if(bk[i]=='0'){
				int cnt1=sum[i-1]-sum[lst],cnt11=sum1[i-1]-sum1[lst];
				// cout<<cnt1<<" "<<cnt11<<" "<<i-1<<" "<<lst<<" "<<(i-1)-lst-cnt1<<" "<<(i-1)-lst-cnt11<<endl;
				cnt+=min(cnt1,cnt11)+min((i-1)-lst-cnt1,(i-1)-lst-cnt11);
				lst=i;
				flag=i;
			}
		}
		for(int i=1;i<=n;i++){
			if(bk[i]=='0'){
				if(s[i]==s1[i]){
					cnt++;
				}
			}
		}
		flag++;
		int cnt1=sum[n]-sum[flag-1],cnt11=sum1[n]-sum1[flag-1];
		cnt+=min(cnt1,cnt11)+min(n-flag+1-cnt1,n-flag+1-cnt11);
		write(cnt);
		puts("");
	}
}

namespace sub3{
	bool check(){
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(bk[i]=='0'){
				cnt++;
			}
		}
		if(cnt!=1){
			return 0;
		}
		cnt=0;
		for(int i=1;i<=n;i++){
			if(bk1[i]=='0'){
				cnt++;
			}
		}
		if(cnt!=1){
			return 0;
		}
		return 1;
	}
	void solve(){
		int id=0,id1=0;
		for(int i=1;i<=n;i++){
			if(bk[i]=='0'){
				id=i;
				bkk[i]=0;
			}
			else{
				bkk[i]=1;
			}
		}
		int ls=0;
		for(int i=1;i<=n;i++){
			if(bkk[i]==0){
				lst[i]=ls;
				ls=i;
			}
		}
		int ans=0;
		int flaggg=0;
		for(int i=1;i<=n;i++){
			if(bkk[i]==0){
				int r=i-1,l=lst[i]+1;
				int cnt1=sum[r]-sum[l-1],cnt11=sum1[r]-sum1[l-1],cnt0=r-l+1-cnt1,cnt00=r-l+1-cnt11;
				if(bk[i]=='0'&&bk1[i]!='0'){
					flaggg=0;
					cnt11+=s1[i]=='1';
					cnt00+=s1[i]=='0';
					if(s[i]!=s1[i]){
						if(s[i]==0&&cnt00){
							flaggg=1;
							cnt00--;
							ans++;
						}
						else if(s[i]==1&&cnt11){
							flaggg=-1;
							cnt11--;
							ans++;
						}
						ans+=(min(cnt1,cnt11)+min(cnt0,cnt00));
					}
					else{
						ans+=(min(cnt1,cnt11)+min(cnt0,cnt00));
					}
				}
				else{
					ans+=(min(cnt1,cnt11)+min(cnt0,cnt00));
				}
			}
		}
		// cout<<id<<" ";
		id++;
		int cnt1=sum[n]-sum[id]+flaggg,cnt11=sum1[n]-sum1[id]-flaggg;
		ans+=min(cnt11,cnt1)+min(n-id-cnt1,n-id-cnt11)+(s[id]==s1[id]);
		
		for(int i=1;i<=n;i++){
			bkk[i]=0;
		}
		for(int i=1;i<=n;i++){
			if(bk1[i]=='0'){
				id1=i;
				bkk[i]=0;
			}
			else{
				bkk[i]=1;
			}
		}
		ls=0;
		for(int i=1;i<=n;i++){
			lst[i]=0;
		}
		for(int i=1;i<=n;i++){
			if(bkk[i]==0){
				lst[i]=ls;
				ls=i;
			}
		}
		int ans1=0;
		flaggg=0;
		for(int i=1;i<=n;i++){
			if(bkk[i]==0){
				int r=i-1,l=lst[i]+1;
				int cnt1=sum[r]-sum[l-1],cnt11=sum1[r]-sum1[l-1],cnt0=r-l+1-cnt1,cnt00=r-l+1-cnt11;
				if(bk[i]!='0'&&bk1[i]=='0'){
					flaggg=0;
					cnt0+=s[i]=='0';
					cnt1+=s[i]=='1';
					if(s[i]!=s1[i]){
						if(s1[i]==0&&cnt0){
							flaggg=1;
							cnt0--;
							ans++;
						}
						else if(s1[i]==1&&cnt1){
							flaggg=-1;
							cnt1--;
							ans++;
						}
						ans1+=(min(cnt1,cnt11)+min(cnt0,cnt00));
					}
					else{
						ans1+=(min(cnt1,cnt11)+min(cnt0,cnt00));
					}
				}
				else{
					ans1+=(min(cnt1,cnt11)+min(cnt0,cnt00));
				}
				// cout<<l<<" "<<r<<" "<<cnt1<<" "<<cnt0<<" "<<cnt11<<" "<<cnt00<<endl;
			}
		}
		// cout<<id1<<endl;
		// cout<<flaggg<<endl;
		id1++;
		cnt1=sum[n]-sum[id1]-flaggg,cnt11=sum1[n]-sum1[id1]+flaggg;
		ans1+=min(cnt11,cnt1)+min(n-id1-cnt1,n-id1-cnt11)+(s[id]==s1[id]);
		// cout<<ans<<" "<<ans1<<endl;
		write(max(ans,ans1));
		puts("");
	}
}

void solve(){
	n=read();
	scanf("%s%s%s%s",s+1,s1+1,bk+1,bk1+1);
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(s[i]=='1');
		sum1[i]=sum1[i-1]+(s1[i]=='1');
	}
	int cnt=0;
	if(n<=10){
		for(int i=1;i<=n;i++){
			c[i]=0;
			c1[i]=0;
		}
		anss=0;
		dfs(1);
		write(anss);
		puts("");
		return ;
	}
	else if(sub1::check()){
		sub1::solve();
		return ;
	}
	else if(sub2::check()){
		sub2::solve();
		return ;
	}
	else if(sub3::check()){
		sub3::solve();
		return ;
	}
	else{
		sub3::solve();
		return ;
	}
	for(int i=1;i<=n;i++){
		sum[i]=0;
		sum1[i]=0;
		lst[i]=0;
		bkk[i]=0;
	}
	return ;
}

signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=1;
	T=read();
	while(T--){
		solve();
	}
	return 0;
} 
