#include<bits/stdc++.h>
#define ll int
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define MAXN 0x3f3f3f3f
using namespace std;
const int maxn=1e5+7;
struct node{
	ll l,r;
};//存储每个0或1能取到的范围 
inline ll read(){
	ll f=1,x=0;char c=getchar();
	while(!isdigit(c)){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(isdigit(c)){
		x=(x<<3)+(x<<1)+int(c-48);
		c=getchar();
	}
	return f*x;
}
ll t,n,ans,pa,pb;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	t=read();
	while(t--){
		n=read(),ans=0;
		string s1,s2,t1,t2;
		cin>>s1>>s2>>t1>>t2;
		if(t1==t2){
			ll zero=0,one=0;
			FOR(i,0,n-1){
				if(t1[i]=='0'&&s1[i]==s2[i]){
					ans++;
					ans+=min(zero,one);
					zero=0,one=0;
				}
				if(t1[i]=='1'){
					if(s1[i]=='0'||s2[i]=='0') zero++;
					if(s1[i]=='1'||s2[i]=='1') one++; 
				}
			}
		}
		else{
			FOR(i,0,n-1){
				if(s1[i]==s2[i]) ans++;
			}
		}
		cout<<ans<<'\n';
	}
	//不是ccf这第一题我写不出来那我这不是废了吗 
}
