#include <cassert>
#include <cctype>
#include <cstdio>
#include <sys/types.h>
#include <tuple>
#include <vector>

#define let const auto
#define mut auto

template<typename T>
using vec = std::vector<T>;
using ull = unsigned long long;
using ll = long long;

using std::tuple;

template<typename T>
T read() {
	T s = 0, w = 1, c = getchar();
	while (!isdigit(c)) {
		if (c == '-') {
			w = -1;
		}
		c = getchar();
	}
	while (isdigit(c)) {
		s = s * 10 + c - '0';
		c = getchar();
	}
	return s * w;
}

class Config {
public:
	uint n;
	vec<bool> s1, s2, t1, t2;
};

uint solve(const Config &);

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);

	mut T = read<uint>();
	while (T--) {
		let n = read<uint>();
		mut config = Config{n, vec<bool>(n), vec<bool>(n), vec<bool>(n), vec<bool>(n)};
		mut c = getchar();
		while (!isdigit(c)) {
			c = getchar();
		}
		for (mut i : config.s1) {
			i = (c == '1');
			c = getchar();
		}
		while (!isdigit(c)) {
			c = getchar();
		}
		for (mut i : config.s2) {
			i = (c == '1');
			c = getchar();
		}
		while (!isdigit(c)) {
			c = getchar();
		}
		for (mut i : config.t1) {
			i = (c == '1');
			c = getchar();
		}
		while (!isdigit(c)) {
			c = getchar();
		}
		for (mut i : config.t2) {
			i = (c == '1');
			c = getchar();
		}
		let ans = solve(config);
		printf("%u\n", ans);
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}

uint solve(const Config &config) {
	mut res = 0u;

	mut pos1 = 0u, pos2 = 0u, tp1 = 0u, tp2 = 0u;
	mut s1_0 = 0u, s1_1 = 0u, s2_0 = 0u, s2_1 = 0u;

	// vec<bool> vis(config.n);

	// init
	// while (pos1 < config.n && config.t1[pos1]) {
	// 	config.s1[pos1] ? s1_1++ : s1_0++;
	// 	pos1++;
	// }
	// while (pos2 < config.n && config.t2[pos2]) {
	// 	config.s2[pos2] ? s2_1++ : s2_0++;
	// 	pos2++;
	// }

	// let temp1 = std::min(s1_0, s2_0), temp2 = std::min(s1_1, s2_1);
	// res += temp1 + temp2;
	// s1_0 -= temp1, s2_0 -= temp1;
	// s1_1 -= temp2, s2_1 -= temp2;

	// printf("%u %u %u %u %u\n", pos1, pos2, temp1, temp2, res);
	// while (pos1 < config.n || pos2 < config.n) {
	// 	if (pos1 < pos2) {
	// 		s1_0 = s1_1 = 0;
	// 		if (config.s1[pos1] && s2_1 || (!config.s1[pos1]) && s2_0) {
	// 			res++;
	// 			config.s1[pos1] ? s2_1-- : s2_0--;
	// 		}
	// 		pos1++;
	// 		while (pos1 < config.n && config.t1[pos1]) {
	// 			config.s1[pos1] ? s1_1++ : s1_0++;
	// 			pos1++;
	// 		}
	// 	} else if (pos2 < pos1) {
	// 		s2_0 = s2_1 = 0;
	// 		if (config.s2[pos2] && s1_1 || (!config.s2[pos2]) && s1_0) {
	// 			res++;
	// 			config.s2[pos2] ? s1_1-- : s1_0--;
	// 		}
	// 		pos2++;
	// 		while (pos2 < config.n && config.t2[pos2]) {
	// 			config.s2[pos2] ? s2_1++ : s2_0++;
	// 			pos2++;
	// 		}
	// 	} else {
	// 		s1_0 = s1_1 = s2_0 = s2_1 = 0;
	// 		res += (config.s1[pos1] == config.s2[pos2]);
	// 		pos1++;
	// 		pos2++;
	// 		while (pos1 < config.n && config.t1[pos1]) {
	// 			config.s1[pos1] ? s1_1++ : s1_0++;
	// 			pos1++;
	// 		}
	// 		while (pos2 < config.n && config.t2[pos2]) {
	// 			config.s2[pos2] ? s2_1++ : s2_0++;
	// 			pos2++;
	// 		}
	// 	}
	// 	let temp1 = std::min(s1_0, s2_0), temp2 = std::min(s1_1, s2_1);
	// 	res += temp1 + temp2;
	// 	s1_0 -= temp1, s2_0 -= temp1;
	// 	s1_1 -= temp2, s2_1 -= temp2;
	// 	printf("%u %u %u %u %u\n", pos1, pos2, temp1, temp2, res);
	// 	// exit(0);
	// }


	for (mut i = 0u; i < config.n; i++) {
		if (pos1 == i) {
			s1_0 = s1_1 = 0;
			while (pos1 < config.n && config.t1[pos1]) {
				config.s1[pos1] ? s1_1++ : s1_0++;
				pos1++;
			}
			pos1++;
		}
		if (pos2 == i) {
			s2_0 = s2_1 = 0;
			while (pos2 < config.n && config.t2[pos2]) {
				config.s2[pos2] ? s2_1++ : s2_0++;
				pos2++;
			}
			pos2++;
		}
		// if (pos1 < config.n && !vis[pos1] && pos1 == pos2) {

		// }
		if ((!config.t1[i]) && !(config.t2[i])) {
			res += (config.s1[i] == config.s2[i]);
		} else if (!config.t1[i]) {
			if (config.s1[i] && s2_1 || (!config.s1[i]) && s2_0) {
				config.s1[i] ? s2_1-- : s2_0--;
				res++;
			}
		} else if(!config.t2[i]) {
			if (config.s2[i] && s1_1 || (!config.s2[i]) && s1_0) {
				config.s2[i] ? s1_1 -- : s1_0--;
				res++;
			}
		} else if (s1_0 && s2_0) {
			res++;
			s1_0--, s2_0--;
		} else if(s1_1 && s2_1){
			res++;
			s2_1--, s1_1--;
		}
	}

	return res;
}