#include<bits/stdc++.h>
using namespace std;
int T,n,ans;
string s1,s2,c,d;
int a[100005],b[100005];
int deal(int l,int r){
	int cnt=0;
	if(l<r){
		sort(a+l,a+r+1);
		sort(b+l,b+r+1);
	}
	for(int i=l;i<=r;i++){
		if(a[i]==b[i])cnt++;
	}
	return cnt;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b)); 
		cin>>n;
		cin>>s1>>s2;
		for(int i=0;i<n;i++){
			if(s1[i]=='1'){
				a[i]=1;
			}
			if(s2[i]=='1'){
				b[i]=1;
			}
		}

		cin>>c>>d;
		ans=0;
		if(c==d){
			int l=0,i;
			for(i=0;i<n-1;i++){
				if(c[i]=='0'){
					if(i>=l){
						ans+=deal(l,i-1);
					}
					if(a[i]==b[i])ans++;
					l=i+1;
				}		
			}
			if(i>=l){
				ans+=deal(l,i-1);
			}
			if(a[i]==b[i])ans++;
			l=i+1;
		}
		else{
			for(int i=0;i<n;i++){
				if(a[i]==b[i])ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
} 
