#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int n;
char s[2][N], t[2][N];
int cnt[2][N][2], tc[2], ll[2];
struct node{
	int l, r, cc[2];
}a[2][N];
int ask(int id, int num, int l, int r){
//	printf("%d %d %d %d\n", id, num, l, r);
//	printf("%d - %d = %d\n", cnt[id][r][num], cnt[id][l-1][num], cnt[id][r][num] - cnt[id][l-1][num]);
	return cnt[id][r][num] - cnt[id][l-1][num]; 
}
void solve(){
	memset(cnt, 0, sizeof(cnt)), memset(tc, 0, sizeof(tc)), memset(ll, 0, sizeof(ll));
	scanf("%d", &n);
	scanf("\n%s\n%s\n%s\n%s", s[0]+1, s[1]+1, t[0]+1, t[1]+1);
	int fl1 = 1, fl2 = 1;
	for(int i = 1; i <= n; i++){
		if(s[0][i] != s[0][i-1]) fl1 = 0;
		if(t[0][i] != t[1][i]) fl2 = 0;
	}
	if(fl1){
		int ans = 0;
		for(int i = 1; i <= n; i++)
			ans += (s[0][i] == s[1][i]);
		printf("%d\n", ans);
		return;
	}
	if(fl2){
		int la = 0;
		for(int i = 1; i <= n; i++)
			if(t[i] - '0' == 0)
				sort(s[0] + la + 1, s[0] + i),
				sort(s[1] + la + 1, s[1] + i),
				la = i;
		if(la != n)
			sort(s[0] + la + 1, s[0] + n + 1),
			sort(s[1] + la + 1, s[1] + n + 1);
		int ans = 0;
		for(int i = 1; i <= n; i++)
			ans += (s[0][i] == s[1][i]);
		printf("%d\n", ans);
		return;
	}
}
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T; scanf("%d", &T);
	while(T--) solve();
	return 0;
}
