#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
ll t,n,ans,sum1,sum2;
char a1[100005],a2[100005],s1[100005],s2[100005];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%lld",&t);
	while(t--){
		memset(a1,0,sizeof(a1));
		memset(a2,0,sizeof(a2));
		memset(s1,0,sizeof(s1));
		memset(s2,0,sizeof(s2));
		scanf("%lld",&n);
		scanf("%s\n%s\n%s\n%s",&a1,&a2,&s1,&s2);
		ans=n;
		int lp1=0,lp2=0;
		for(int i=0;i<n;i++){
			if(a1[i]!=a2[i]){
				bool flag=0;
				if(s1[i]!='0'){
					int cmp=i;
					while(s1[++cmp]!='0'&&cmp<n)if(a1[cmp]==a2[i])swap(a1[cmp],a1[i]),flag=1;
				}if(s2[i]!='0'&&!flag){
					int cmp=i;
					while(s2[++cmp]!='0'&&cmp<n)if(a2[cmp]==a1[i])swap(a2[cmp],a2[i]),flag=1;
				}if(!flag)ans--;
			}
		}printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
