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

using namespace std;

const ll N = 1e5+5;

ll T,n,nxt1[N],nxt2[N],n0[N],n1[N],n2[N],n3[N];
bool vis1[N],vis2[N];
char s1[N],s2[N],t1[N],t2[N];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>T;
	
	while(T--){
		cin>>n; 
		for(int i=1;i<=n;i++)cin>>s1[i];
		for(int i=1;i<=n;i++)cin>>s2[i];
		for(int i=1;i<=n;i++)cin>>t1[i];
		for(int i=1;i<=n;i++)cin>>t2[i];
		
		list<ll> q1,q2;
		for(int i=1;i<=n;i++)
			q1.push_back(i);
			
		for(int i=1;i<=n;i++)
			q2.push_back(i);
		
		ll ans=0;
		while(!q1.empty() && !q2.empty()){
			ll x=q1.front(),y=q2.front();
			
			if(s1[x]==s2[y]){ans++,q1.pop_front(),q2.pop_front();continue;}
			
			ll tmp=0;
			if(t1[x]=='1'){
				stack<ll> st; 
				while(!q1.empty()){
					if(t1[q1.front()]=='0')break;
					if(s1[q1.front()]==s2[y])break;
					st.push(q1.front()),q1.pop_front();
				}
				if(!q1.empty() && t1[q1.front()]=='1')ans++,q1.pop_front(),q2.pop_front(),tmp=1;
				while(!st.empty())q1.push_front(st.top()),st.pop();
			}
			if(t2[x]=='1' && !tmp){
				stack<ll> st; 
				while(!q2.empty()){
					if(t2[q2.front()]=='0')break;
					if(s2[q2.front()]==s1[x])break;
					st.push(q2.front()),q2.pop_front();
				}
				if(!q2.empty() && t2[q2.front()]=='1')ans++,q2.pop_front(),q1.pop_front(),tmp=1;
				while(!st.empty())q2.push_front(st.top()),st.pop();
			}
			if(!tmp)q1.pop_front(),q2.pop_front(); 
		} 
		cout<<ans<<"\n";
	}
	return 0;
}
