#include <iostream>
#include <algorithm>

using namespace std;

const int N=1e5+5;

int t,n;
char s1[N],s2[N],t1[N],t2[N];

bool check(char *s,char *t,int c){
	for (int i=1,c1=0;i<=n;i++){
		c1+=s[i]=='1',c1-=c>>i-1&1;
		if (i==n||t[i]=='0'||t[i+1]=='0')
			if (c1) return 0;
	}
	return 1;
}

int main(){
	freopen("edit.in","r",stdin),freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>t;
	while (t--){
		cin>>n;
		cin>>s1+1>>s2+1>>t1+1>>t2+1;
		int ans=0;
		if (n<=10){
			for (int c1=0;c1<1<<n;c1++)
				for (int c2=0;c2<1<<n;c2++)
					if (check(s1,t1,c1)&&check(s2,t2,c2))
						ans=max(ans,n-__builtin_popcount(c1^c2));
			cout<<ans<<"\n";
		}
		else{
			for (int i=1,lst=0;i<=n;i++)
				if (i==n||t1[i]=='0'||t1[i+1]=='0')
					sort(s1+lst+1,s1+i+1),
					sort(s2+lst+1,s2+i+1),
					lst=i;
			for (int i=1;i<=n;i++) ans+=s1[i]==s2[i];
			cout<<ans<<"\n";
		}
	}
	cout<<flush,fclose(stdin),fclose(stdout);
	return 0;
}
