//Author:Dream_Flynn(luogu uid=578398)
#include<bits/stdc++.h>
using namespace std;
/*inline int read(){
	int k=0;
	bool f=false;
	char c=getchar();
	while(!isdigit(c)){
		f=(f||c=='-');
		c=getchar();
	}
	while(isdigit(c)){
		k=(k<<3)+(k<<1)+(c^48);
		c=getchar();
	}
	return f?-k:k;
}
inline void write(int d,char end_ch='\n'){
	if(d<0){
		d=-d;
		putchar('-');
	}
	int stk[32],top=0;
	do{
		top++;
		stk[top]=d%10;
		d/=10;
	}while(d);
	for(int i=top;i;i--){
		putchar(stk[i]^48);
	}
	putchar(end_ch);
}*/
int n,ans;
string s1,s2,t1,t2;
namespace PlanBF{
	struct Pr{
		//int x,y;
		string x,y;
	};
	//bool mp[2000005];
	map<string,bool> mp;
	queue<Pr> q;
	inline void check(string str1,string str2){
		int res=0;
		for(int i=1;i<=n;i++){
			if(str1[i]==str2[i]){
				res++;
			}
		}
		ans=max(res,ans);
	}
	void main(){
		mp.clear();
		ans=0;
		/*int S1=0,S2=0,T1=0,T2=0;
		for(int i=1;i<=n;i++){
			S1+=(s1[i]^48)<<(i-1);
			S2+=(s2[i]^48)<<(i-1);
			T1+=(t1[i]^48)<<(i-1);
			T2+=(t2[i]^48)<<(i-1);
		}*/
		//cerr<<S1<<" "<<S2<<endl;
		//q.push({S1,S2});
		q.push({s1,s2});
		while(!q.empty()){
			Pr tmp=q.front();
			q.pop();
			check(tmp.x,tmp.y);
			mp[tmp.x+tmp.y]=1;
			string nx=tmp.x,ny=tmp.y;
			for(int i=1;i<n;i++){
				if(t1[i]=='1'&&t1[i+1]=='1'){
					nx=tmp.x;
					swap(nx[i],nx[i+1]);
					if(!mp[nx+ny]){
						q.push({nx,ny});
					}
				}
			}
			for(int i=1;i<n;i++){
				if(t2[i]=='1'&&t2[i+1]=='1'){
					ny=tmp.y;
					swap(ny[i],ny[i+1]);
					if(!mp[nx+ny]){
						q.push({nx,ny});
					}
				}
			}
		}
		//cerr<<"\tqewuykfgdws";
		cout<<ans<<'\n';
	}
}
namespace PlanA{
	void main(){
		int ans=0;
		for(int i=1;i<=n;i++){
			if(s2[i]==s1[i]){
				ans++;
			}
		}
		cout<<ans<<'\n';
	}
}
namespace PlanB{
	const int N=1e5+5;
	int s1cnt1=0,s1cnt0=0,s2cnt1=0,s2cnt0=0;
	void main(){
		ans=s1cnt1=s1cnt0=s2cnt1=s2cnt0=0;
		n++;
		t1+="0";
		t2+="0";
		for(int i=1;i<=n;i++){
			if(t1[i]=='1'){
				if(s1[i]=='1'){
					s1cnt1++;
				}
				else{
					s1cnt0++;
				}
				if(s2[i]=='1'){
					s2cnt1++;
				}
				else{
					s2cnt0++;
				}
			}
			else{
				ans+=min(s1cnt1,s2cnt1)+min(s1cnt0,s2cnt0);
				s1cnt1=s1cnt0=s2cnt1=s2cnt0=0;
			}
		}
		for(int i=1;i<n;i++){
			if(t1[i]=='0'){
				ans+=(s1[i]==s2[i])?1:0;
			}
		}
		cout<<ans<<'\n';
	}
}
namespace PlanC{
	int ss1[100005][2],ss2[100005][2];
	void main(int s1pos,int s2pos){
		if(s1pos<s2pos){
			swap(s1pos,s2pos);
			swap(s1,s2);
			swap(t1,t2);
		}
		ans=0;
		ss1[0][0]=ss1[0][1]=ss2[0][0]=ss2[0][1]=0;
		for(int i=1;i<=n;i++){
			ss1[i][0]=ss1[i-1][0];
			ss1[i][1]=ss1[i-1][1];
			ss2[i][0]=ss2[i-1][0];
			ss2[i][1]=ss2[i-1][1];
			ss1[i][s1[i]-'0']++;
			ss2[i][s2[i]-'0']++;
		}
		int L=s1pos,R=s2pos;
		int s1l0cnt=ss1[R][0],s1r0cnt=ss1[n][0]-ss1[R-1][0];
		int s2l0cnt=ss2[L][0],s2r0cnt=ss2[n][0]-ss2[L-1][0];
		int s1l1cnt=ss1[R][1],s1r1cnt=ss1[n][1]-ss1[R-1][1];
		int s2l1cnt=ss2[L][1],s2r1cnt=ss2[n][1]-ss2[L-1][1];
		ans+=min(s1l0cnt,s2l0cnt)+min(s1l1cnt,s2l1cnt);
		int s1m0cnt=s1l0cnt-min(s1l0cnt,s2l0cnt);
		int s1m1cnt=s1l1cnt-min(s1l1cnt,s2l1cnt);
		ans+=min(s1r0cnt,s2r0cnt)+min(s1r1cnt,s2r1cnt);
		int s2m0cnt=s2r0cnt-min(s1r0cnt,s2r0cnt);
		int s2m1cnt=s2r1cnt-min(s1r1cnt,s2r1cnt);
		ans+=min(s1m0cnt,s2m0cnt)+min(s1m1cnt,s2m1cnt);
		cout<<ans<<'\n';
		//xie le 30 hang,mei guo yang li,xin tai beng le
	}
}
void Dream_Flynn_T1(){
	cin>>n>>s1>>s2>>t1>>t2;
	s1=" "+s1;
	s2=" "+s2;
	t1=" "+t1;
	t2=" "+t2;
	if(n<=10){
		PlanBF::main();
		return;
	}
	if(t1==t2){
		PlanB::main();
		return;
	}
	bool s1_all_same=true,s1_0cnt=0,s2_0cnt=0,s1_0pos,s2_0pos;
	for(int i=2;i<=n;i++){
		if(s1[i]!=s1[i-1]){
			s1_all_same=false;
			break;
		}
		if(t1[i]=='0'){
			s1_0cnt++;
			s1_0pos=i;
		}
		if(t2[i]=='0'){
			s2_0cnt++;
			s2_0pos=i;
		}
	}
	if(s1_all_same){
		PlanA::main();
		return;
	}
	/*if(s1_0cnt==1&&s2_0cnt==1){
		PlanC::main(s1_0pos,s2_0pos);
		return;
	}*/
	PlanA::main();
}
int main(){
	freopen("edit.in","r",stdin);
	//freopen("edit2.in","r",stdin);//freopen()//feropen()itn
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		Dream_Flynn_T1();
	}
	return 0;
}

//wo xian zai hen mi huo,t1 dao di zeng me xie?

//hao nan,tai cai le,bu hui,qaq
