#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define _rep(i,a,b) for(int i=(a);i>=(b);--i)
#define eb emplace_back
#define MISAKA main
#define FIO(FILE) freopen(FILE".in","r",stdin),freopen(FILE".out","w",stdout)
using namespace std;
bool __st;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
} 
const int N=1e5+10,mod=998244353;
int n,c[2][2],p[N];char s[2][N],t[2][N],a[N];
int calc(){
	int sum=0;
	rep(i,1,n) a[p[i]]=s[0][i];
	rep(i,1,n){
		if(t[1][i]=='0'){
			sum+=s[1][i]==a[i];
			continue;
		}
		int j=i,p=0,q=0;
		while(j<=n&&t[1][j+1]=='1') j++;
		rep(k,i,j) p+=a[k]=='0',q+=s[1][k]=='0';
		sum+=min(p,q)+min(j-i+1-p,j-i+1-q);
		i=j;
	}
	return sum;
}
void misaka(){
	n=read();
	rep(i,0,1) scanf("%s",s[i]+1);
	rep(i,0,1) scanf("%s",t[i]+1);
	rep(i,0,1)rep(j,0,1) c[i][j]=0;
	int ans=0,f0=1,f1=1;
	rep(i,1,n) p[i]=i;
	if(n<=10){
		do{
			int flag=1;
			rep(i,1,n)if(t[0][i]=='0'&&p[i]!=i){
				flag=0;
				break;
			}
			if(!flag) continue;
			ans=max(ans,calc());
		}while(next_permutation(p+1,p+n+1));
		printf("%d\n",ans);
		return;
	}
	printf("%d\n",calc());
}
bool __ed;
signed MISAKA(){
	FIO("edit");
	int T=read();
	while(T--) misaka();
	return 0;
}

