#include <bits/stdc++.h>
using namespace std;

int n;
int s1[100007],s2[100007];
int t1[100007],t2[100007];
int q1[100007],q2[100007];
bool x[100007];
int cnt1, cnt2;

void read() {
	cin >> n;
	string ss1,ss2,tt1,tt2;
	cin >> ss1;
	cin >> ss2;
	cin >> tt1;
	cin >> tt2;

	for (register int i=0; i<n; ++i)
		s1[i+1] = ss1[i]-'0';
	for (register int i=0; i<n; ++i)
		s2[i+1] = ss2[i]-'0';
	for (register int i=0; i<n; ++i) {
		if (tt1[i]=='0')
			t1[++cnt1] = i+1;
	}
	for (register int i=0; i<n; ++i) {
		if (tt2[i]=='0')
			t2[++cnt2] = i+1;
	}
}


void solve() {
	if (cnt1!=0) {
		t1[++cnt1] = n+1;
		t2[++cnt2] = n+1;
		for (register int i=0; i<cnt1; ++i) {
			sort(s1+t1[i]+1,s1+t1[i+1]);
			sort(s2+t2[i]+1,s2+t2[i+1]);
		}
	}
	else {
		sort(s1+1,s1+n+1);
		sort(s2+1,s2+n+1);
	}
	
	/*for (register int i=1; i<=n; ++i)
		cout << s1[i];
	cout << endl ;
	for (register int i=1; i<=n; ++i)
		cout << s2[i];*/
	
	int ans = 0;
	for (register int i=1; i<=n; ++i)
		if(s1[i] == s2[i]) ans++;
	cout << ans << endl;

}

int main () {

	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	
	int T;
	cin >> T;
	while (T--){
		read();
		solve();
	}

	return 0;
}
