#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int T,n,tot1[N],tot2[N],cnt1,cnt2;
int L1[N],L2[N],R1[N],R2[N],len1[N],len2[N],bl1[N],bl2[N];
int del10[N],del11[N],del20[N],del21[N];
string s1,s2,t1,t2;char c1[N],c2[N];
inline void mian(){
	memset(bl1,0,sizeof bl1);
	memset(bl2,0,sizeof bl2);
	memset(len1,0,sizeof len1);
	memset(len2,0,sizeof len2);
	memset(del10,0,sizeof del10);
	memset(del11,0,sizeof del11);
	memset(del20,0,sizeof del20);
	memset(del21,0,sizeof del21);
	cnt1=cnt2=0;
	cin>>n>>s1>>s2>>t1>>t2;int ans=0;
	s1='0'+s1,s2='0'+s2,t1='0'+t1,t2='0'+t2;
	for(int i=1;i<=n;i++){
		if(t1[i]==49&&t1[i-1]==48)L1[++cnt1]=i;
		if(t2[i]==49&&t2[i-1]==48)L2[++cnt2]=i;
		if(t1[i]==48&&t1[i-1]==49){R1[cnt1]=i-1;}
		else if(t1[i]==49)bl1[i]=cnt1;
		if(t2[i]==48&&t2[i-1]==49){R2[cnt2]=i-1;}
		else if(t2[i]==49)bl2[i]=cnt2;
		tot1[i]=tot1[i-1]+s1[i]-48;
		tot2[i]=tot2[i-1]+s2[i]-48;
		len1[bl1[i]]++,len2[bl2[i]]++;
	}if(!R1[cnt1])R1[cnt1]=n;if(!R2[cnt2])R2[cnt2]=n;
	for(int i=1;i<=n;i++){
		int pos1=bl1[i],pos2=bl2[i];
		if(!pos1&&!pos2)ans+=(s1[i]!=s2[i]);
		else if(pos1&&pos2){
			int cnt1=tot1[R1[pos1]]-tot1[L1[pos1]-1];
			int cnt2=tot2[R2[pos2]]-tot2[L2[pos2]-1];
			int zr1=len1[pos1]-cnt1-del10[pos1],zr2=len2[pos2]-cnt2-del20[pos2];
			cnt1-=del11[pos1];cnt2-=del21[pos2];
			if(zr1&&zr2)del20[pos2]++,del10[pos1]++;
			else if(cnt1&&cnt2)del21[pos2]++,del11[pos1]++;
			else ans++;
		}
		else if(pos1){
			int cnt=tot1[R1[pos1]]-tot1[L1[pos1]-1];
			int zr=len1[pos1]-cnt-del10[pos1];
			cnt-=del11[pos1];
			if(s2[i]==48)ans+=(!zr),del10[pos1]+=(zr>0);
			else ans+=!cnt,del11[pos1]+=(cnt>0);
		}
		else{
			int cnt=tot2[R2[pos2]]-tot2[L2[pos2]-1];
			int zr=len2[pos2]-cnt-del20[pos2];
			cnt-=del21[pos2];
			if(s1[i]==48)ans+=(!zr),del20[pos2]+=(zr>0);
			else ans+=!cnt,del21[pos2]+=(cnt>0);
		}
	}cout<<n-ans<<'\n';
	for(int i=1;i<=cnt1;i++)L1[i]=R1[i]=0;
	for(int i=1;i<=cnt2;i++)L2[i]=R2[i]=0;
}
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--)mian();
	return 0;
}
