#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int t,n,ans;
string s1,s2,t1,t2;
int a[N],b[N];
void work(){
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	ans=0;
	cin>>n;
	cin>>s1>>s2>>t1>>t2;
	for(int i=0;i<n;i++){
		if(s1[i]=='1') a[i]++;
		if(s2[i]=='1') b[i]++;
		a[i]+=a[i-1];
		b[i]+=b[i-1];
	}
	if(a[n-1]==n){
		cout<<b[n-1]<<endl;
		return ;
	}
	if(a[n-1]==0){
		cout<<n-b[n-1]<<endl;
		return ;
	}
	if(t1==t2){
		int js=0;
		for(int i=0;i<=n;i++){
			if(t1[i]=='0'){
				if(s1[i]==s2[i]) ans++;
				ans+=i-js+1-abs(a[i-1]-b[i-1]);	
			}
		}
		cout<<ans<<endl;
		return ;
	}
	cout<<a[n-1]<<endl;
	return;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin>>t; 
	while(t--) work();
	return 0;
}

