#include<bits/stdc++.h>
using namespace std;
const int N=1e5+2; 
int T,n;
char c1[N],c2[N],t1[N],t2[N];
bool a[N],b[N];
void sloveA(){
	int ans=0;
	for(int i=1;i<=n;i++)ans+=(a[i]==b[i]);
	cout<<ans<<"\n";
}
void sloveB(){
	n++,t1[n]='0',a[n]=0,b[n]=1;
	int ans=n;
	for(int i=1,cnt1=0,cnt2=0;i<=n;i++){
		if(t1[i]=='0'){
			ans-=abs(cnt1-cnt2),cnt1=cnt2=0;
			if(a[i]!=b[i])ans--;
		}
		else cnt1+=a[i],cnt2+=b[i];
	}
	cout<<ans<<"\n";
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	for(cin>>T;T--;){
		cin>>n;
		cin>>c1+1>>c2+1>>t1+1>>t2+1;
		bool A=1,B=1;
		for(int i=1;i<=n;i++){
			a[i]=c1[i]-'0',b[i]=c2[i]-'0';
			if(i>1&&a[i]!=a[i-1])A=0;
			if(t1[i]!=t2[i])B=0;
		}
		if(A)sloveA();
		else if(B)sloveB();
		else cout<<"0\n";
	}
	return 0;
}
