#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define F(i,j,k) for(int i=j;i<=k;i++)
const int N=1e5+5;
int T,n,m;
string s1,s2;
int t1[N],t2[N];
struct node{
	int col,num,a,b;
}x[N],y[N];
int tx,ty;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	/*
	1
	10
	0110111100
	1111111100
	1110000100
	0110111011
	*/
	while(T--){
		cin>>n>>s1>>s2;
		set<char> s;
		int same=0;
		for(int i=0;i<n;i++){
			s.insert(s1[i]);
		}int A=0,B=0;
		for(int i=0;i<n;i++){
			char x;
			cin>>x;
			t1[i]=x-'0';
			if(!t1[i]) A++;
		}
		for(int i=0;i<n;i++){
			char x;
			cin>>x;
			t2[i]=x-'0';
			if(!t2[i]) B++;
			if(t1[i]==t2[i]) same++;
		}
		if(same==n){
			int ans=0;
			for(int i=0;i<n;i++){
				if(!t1[i]) ans+=(s1[i]==s2[i]?1:0);
				else{
					int r=i,a[2]={},b[2]={};
					while(t1[r]&&r<n){
						a[s1[r]-'0']++;
						b[s2[r]-'0']++;
						r++;
					}
					r--;
					ans+=min(a[0],b[0])+min(a[1],b[1]);
					i=r;
				}
			}cout<<ans<<'\n';
		}
		else{
			int ans=0;
			for(int i=0;i<n;i++){
				if(s1[i]==s2[i]) ans++;
			}cout<<ans<<'\n';
		}
	}
	return 0;
}

