# include<iostream>
# include<cstdio>
# include<string>
# include<cmath>
using namespace std;

const int N=1e5+2;
int t,n,a,b,ans,tmp;
string s1,s2,t1,t2;

void solve(){
	ans=0;
	cin>>n>>s1>>s2>>t1>>t2;
	if(t1==t2){
		tmp=-1;a=b=0;
		for(int i=0;i<=n;++i){
			if(i==n){
				ans+=i-tmp-1-abs(a-b);
				break;
			}
			if(t1[i]=='0'){
				ans+=i-tmp-1-abs(a-b);
				if(s1[i]==s2[i]) ans++;
				a=b=0;tmp=i;
			}
			else{
				if(s1[i]=='1') ++a;
				if(s2[i]=='1') ++b;
			}
		}
	}
	else{
		for(int i=0;i<n;++i)
			if(s2[i]==s1[0]) ++ans;
	}
	cout<<ans<<endl;
}

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--) solve();
	return 0;
}
