#include <iostream>
#include <cstring>

using namespace std;

int t, n;

int cnt [2], set [2];

int num [2] [100005] [2];

char str [2] [100005], lim [2] [100005];

string arr [2] [100005];

void dfs (int val, int p, string s, int num0, int num1, int setnum) {
	if (p == n + 1) {
		arr [val] [++ cnt [val]] = s;
		return;
	}
	if (lim [val] [p] == '1') {
		if (num0 < num [val] [setnum] [0])
			dfs (val, p + 1, s + '0', num0 + 1, num1, setnum);
		if (num1 < num [val] [setnum] [1])
			dfs (val, p + 1, s + '1', num0, num1 + 1, setnum);
	} else
		dfs (val, p + 1, s + str [val] [p], 0, 0, setnum + 1);
}

int main () {
	freopen ("edit.in", "r", stdin),
	freopen ("edit.out", "w", stdout);
	scanf ("%d", bitand t);
	while (t --) {
		memset (num, 0, sizeof num),
		set [0] = set [1] = 1,
		scanf ("%d%s%s%s%s", bitand n, str [0] + 1, str [1] + 1, lim [0] + 1, lim [1] + 1);
		if (string (str [0] + 1).find ('0') == string::npos) {
			int tot = 0;
			for (int i = 1; i <= n; ++ i)
				tot += (str [1] [i] == '1');
			printf ("%d\n", tot);
			continue;
		}
		if (string (str [0] + 1).find ('1') == string::npos) {
			int tot = 0;
			for (int i = 1; i <= n; ++ i)
				tot += (str [1] [i] == '0');
			printf ("%d\n", tot);
			continue;
		}
		for (int i = 1; i <= n; ++ i) {
			if (lim [0] [i] == '1')
				num [0] [set [0]] [0] += (str [0] [i] == '0'),
				num [0] [set [0]] [1] += (str [0] [i] == '1');
			else
				++ set [0];
			if (lim [1] [i] == '1')
				num [1] [set [1]] [0] += (str [1] [i] == '0'),
				num [1] [set [1]] [1] += (str [1] [i] == '1');
			else
				++ set [1];
		}
		if (string (lim [0] + 1) == string (lim [1] + 1)) {
			int tot = 0;
			for (int i = 1; i <= set [0]; ++ i)
				tot += min (num [0] [i] [0], num [1] [i] [0]) + min (num [0] [i] [1], num [1] [i] [1]);
			for (int i = 1; i <= n; ++ i)
				if (lim [0] [i] == '0')
					tot += (str [0] [i] == str [1] [i]);
			printf ("%d\n", tot);
			continue;
		}
		cnt [0] = cnt [1] = 0,
		dfs (0, 1, "", 0, 0, 1),
		dfs (1, 1, "", 0, 0, 1);
//		cout << "begin:" << endl;
//		for (int i = 1; i <= cnt [0]; ++ i)
//			cout << arr [0] [i] << endl;
//		cout << "then: " << endl;
//		for (int i = 1; i <= cnt [1]; ++ i)
//			cout << arr [1] [i] << endl;
//		cout << "end." << endl;
		int ans = 0;
		for (int i = 1; i <= cnt [0]; ++ i)
			for (int j = 1; j <= cnt [1]; ++ j) {
				int tot = 0;
				for (int k = 0; k < n; ++ k)
					tot += (arr [0] [i] [k] == arr [1] [j] [k]);
//				cout << arr [0] [i] << ' ' << arr [1] [j] << ' ' << tot << endl;
				if (tot > ans)
					ans = tot;
			}
		printf ("%d\n", ans);
	}
	return 0;
} 
