#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int M=1e5+5;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T,n;cin>>T;
	string s1,s2,t1,t2;
	while(T--){
		int E1=0,E2=0,ans=0;
		cin>>n;
		cin>>s1>>s2>>t1>>t2;
		for(int i=0;i<n-1;++i)
			if(s1[i]!=s1[i+1]){
				E1=1;
				break;
			}
		for(int i=0;i<n-1;++i)
			if(s2[i]!=s2[i+1]){
				E2=1;
				break;
			}
		if(!(E2&&E1)){
			for(int i=0;i<n;++i)
				if(s1[i]==s2[i])
					++ans;
			cout<<ans<<"\n";
			continue;
		}
		for(int i=0,E=0;i<n;++i){
			E=0;
			if(s1[i]==s2[i])
				continue;
			for(int j=i;j<n;++j){
				if(t1[j]=='0') E1=0;
				if(!E1) break;
				if(j>i&&s1[i]!=s2[i]){
					if(s1[j]==s2[i]&&t1[j]=='1'&&E1){
						swap(s1[i],s1[j]);
						E=1;
						break;
					}
				}				
			}
			if(E) continue;
			for(int j=i;j<n;++j){
				if(t2[j]=='0') E2=0;
				if(!E2) break;
				if(j>i&&s1[i]!=s2[i]){
					if(s2[j]==s1[i]&&t2[j]=='1'&&E2){
						swap(s2[i],s2[j]);
					}
				}				
			}			
		}
		for(int i=0;i<n;++i){
			if(s1[i]==s2[i])
				++ans;
		}
		cout<<ans<<"\n";
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
