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

int n; string s1, s2, t1, t2;
il void solveA() {
	long long res = 0;
	for (int i = 0; i < n; i ++)
		if (s2[i] == s1[i])
			res ++;
	cout << res << "\n";
	return ;
}
il void solveB() {
	int cnts1[2], cnts2[2];
	memset(cnts1, 0, sizeof cnts1);
	memset(cnts2, 0, sizeof cnts2);
	long long res = 0;
	for (int i = 0; i < n; i ++) {
		if (t1[i] == '0') {
			if (s1[i] == s2[i])
				res ++;
			res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]);
			memset(cnts1, 0, sizeof cnts1);
			memset(cnts2, 0, sizeof cnts2);
			continue;
		}
		if (s1[i] == '0') cnts1[0] ++;
		else cnts1[1] ++;
		if (s2[i] == '0') cnts2[0] ++;
		else cnts2[1] ++;
		if (i == n - 1) 
			res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]);
	}
	cout << res << "\n";
	return ;
}
il void solveC() {
	int poss1 = -1, poss2 = -1;
	for (int i = 0; i < n; i ++) {
		if (t1[i] == '0') poss1 = i;
		if (t2[i] == '0') poss2 = i;
	}
	long long res = 0;
	int cnts1[2], cnts2[2];
	memset(cnts1, 0, sizeof cnts1);
	memset(cnts2, 0, sizeof cnts2);
	if (poss1 > poss2) swap(s1, s2), swap(poss1, poss2), swap(t1, t2);
	
	for (int i = 0; i < poss1; i ++)
		if (s1[i] == '0') cnts1[0] ++;
		else cnts1[1] ++;
	for (int i = 0; i < poss2; i ++)
		if (s2[i] == '0') cnts2[0] ++;
		else cnts2[1] ++;
	res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]); //[0, poss1)
	cnts2[0] = max(0, cnts2[0] - cnts1[0]);
	cnts2[1] = max(0, cnts2[1] - cnts1[1]);
	
	if (s1[poss1] == '0' && cnts2[0] > 0) res ++, cnts2[0] --;
	if (s1[poss1] == '1' && cnts2[1] > 0) res ++, cnts2[1] --;
	memset(cnts1, 0, sizeof cnts1);
	
	for (int i = poss1 + 1; i < n; i ++)
		if (s1[i] == '0') cnts1[0] ++;
		else cnts1[1] ++;
	res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]); //(poss1, poss2)
	cnts1[0] = max(0, cnts1[0] - cnts2[0]);
	cnts1[1] = max(0, cnts1[1] - cnts2[1]);
	
	if (s2[poss2] == '0' && cnts1[0] > 0) res ++, cnts1[0] --;
	if (s2[poss2] == '1' && cnts1[1] > 0) res ++, cnts1[1] --;
	memset(cnts2, 0, sizeof cnts2);
	
	for (int i = poss2 + 1; i < n; i ++)
		if (s2[i] == '0') cnts2[0] ++;
		else cnts2[1] ++;
	res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]); //(poss2, n - 1]
	cout << res << "\n";
	return ;
}
il void solveall() {
	long long cnts1[2], cnts2[2];
	memset(cnts1, 0, sizeof cnts1);
	memset(cnts2, 0, sizeof cnts2);
	long long res = 0;
	for (int i = 0; i < n; i ++) {
		if (t1[i] == '0') {
			if (t2[i] == '0') {
				if (s1[i] == s2[i]) res ++;
				res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]);
			} else {
				if (s2[i] == '0') cnts2[0] ++;
				else cnts2[1] ++;
				res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]);
				if (s1[i] == '0' && cnts2[0] > cnts1[0]) res ++;
				if (s1[i] == '1' && cnts2[1] > cnts1[1]) res ++;
			}
			memset(cnts1, 0, sizeof cnts1);
			memset(cnts2, 0, sizeof cnts2);
			continue;
		} else if (t2[i] == '0') {
			if (s1[i] == '0') cnts1[0] ++;
			else cnts1[1] ++;
			res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]);
			if (s2[i] == '0' && cnts1[0] > cnts2[0]) res ++;
			if (s2[i] == '1' && cnts1[1] > cnts2[1]) res ++;
			memset(cnts1, 0, sizeof cnts1);
			memset(cnts2, 0, sizeof cnts2);
			continue;
		}
		if (s1[i] == '0') cnts1[0] ++;
		else cnts1[1] ++;
		if (s2[i] == '0') cnts2[0] ++;
		else cnts2[1] ++;
	}
	res += min(cnts1[0], cnts2[0]) + min(cnts1[1], cnts2[1]);
	cout << res << "\n";
}
il void solve() {
	cin >> n >> s1 >> s2 >> t1 >> t2;
	bool flagA = 1, flagB = 1, flagC = 1;
	int cntt1 = 0, cntt2 = 0;
	for (int i = 0; i < n; i ++) {
		if (i < n - 1 && s1[i] != s1[i + 1]) flagA = 0;
		if (t1[i] != t2[i]) flagB = 0;
		if (t1[i] == '0') cntt1 ++;
		if (t2[i] == '0') cntt2 ++;
	}
	if (cntt1 != 1 || cntt2 != 1) flagC = 0;
	if (flagA) { solveA(); return ; }
	else if (flagB) { solveB(); return ; }
	else if (flagC) { solveC(); return ; }
	else { solveall(); return ;	}
}
signed main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T; cin >> T;
	while (T --) solve();
	return 0;
}

/*
左边的左边有小孩哥 
一直在推拉键盘
口中还在念念有词地施法

11:27 小孩哥开始哼歌 

12:38 小孩哥跪在椅子上看题，被监考员制止了 

12:40 小孩哥被监考员警告，前者尝试与后者交涉，未果
	  小孩哥被带出考场，大快人心
	  
12:45 小孩哥返场 
*/
