#include <bits/stdc++.h>
#define LL long long
using namespace std;
int getin() {
	int ans = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	do {
		ans = (ans << 1) + (ans << 3) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return ans * f;
}
const int N = 1e+05 + 100;
int T, n, pre, nex[N]; 
bool b[N];
char s1[N], s2[N], t1[N], t2[N];
//bool check(int l, int r, int flag) {
//	if (flag == 1) {
//		for (int i = l + 1; i < r; ++i) {
//			if (t1[i] == '0')
//				return false;
//		}
//	} else 
//		for (int i = l + 1; i < r; ++i) {
//			if (t2[i] == '0')
//				return false;
//		}
//	return true;
//}

//void puto(char s[]) {
//	for (int i = 1; i <= strlen(s + 1); ++i)
//		cout<<s[i];
//	cout<<endl;
//}

void solve() {
	n = getin();
	int cnt = 0, ans = 0, cnt0 = 0, cnt2 = 0, cnt20 = 0, c1 = 0, c2 = 0, pos1=0,pos2=0;
	for (int i = 1; i <= n; ++i){
		s1[i] = getchar();
		if (s1[i] == '1') 
			++cnt;
		else cnt0++;
	}
//	puto(s1);
	getchar();
	for (int i = 1; i <= n; ++i) {
		s2[i] = getchar();
		if (s1[i] == s2[i]) 
			++ans;
		else { // 不相同的标记 
			b[i] = 1;
		}
	}
	getchar();
//	puto(s2);
	// 特殊测试点A
	if (cnt == n || cnt0 == n) {
		scanf("%s", t1 + 1);
		scanf("%s", t2 + 1);
		printf("%d\n", ans);
	} else {
		for (int i = 1; i <= n; ++i){
			t1[i] = getchar();
			if (t1[i] == '0') {
				c1++;
				pos1=i;
			}
				
			// 不能换的 
			if (i > 2 && t1[i] == '0' && t1[i-2] == '0')
				t1[i-1] = '0';
		}
//		puto(t1);
		if (t1[n-1] == '0')
			t1[n] = '0'; 
		getchar();
		
		for (int i = 1; i <= n; ++i) {
			t2[i] = getchar();
			if (t2[i] == '0') 
			{
				c2++;
				pos2 = i;
			}
				
			if (i > 2 && t2[i] == '0' && t2[i-2] == '0')
				t2[i-1] = '0'; 
		}
		getchar();
//		puto(t2);
		if (t2[n-1] == '0')
			t2[n] = '0'; 
		
		if (strcmp(t1 + 1, t2 + 1) == 0) {
			ans = 0;
			cnt = 0, cnt0 = 0, cnt2 = 0, cnt20 = 0;
			for (int i = 1; i <= n + 1; ++i) {
				if (t1[i] == '0' || i == n + 1) {
					ans += min(cnt, cnt2) + min(cnt0, cnt20);
					cnt = 0, cnt0 = 0, cnt2 = 0, cnt20 = 0;
					continue;
				} else {
					if (s1[i] == '1')
						++cnt;
					else ++cnt0;
					if (s2[i] == '1')
						++cnt2;
					else ++cnt20;
				}
			}
			printf("%d\n", ans); 
			return;
		} else if (c1 == 1 && c1 == c2) {
//			cout<<"aaa"<<endl;
			if (pos1 == pos2) 
			{
				printf("%d\n", ans);
				return;
			} else {
				if (!b[pos1] && !b[pos2]) {
					printf("%d\n", ans);
					return;
				}
			}
		}
		
		for (int i = 1; i <= n; ++i) {
			if (b[i] == 1 && (t1[i] == '1' || t2[i] == '1')) {
				nex[pre] = i; // 链式存储 
				pre = i; // 方便下一次标记 
			} else b[i] = 0;
		}
		
		int t = nex[0], xia = 0;
		bool flag = false;
		while (t > 0) {
			xia = nex[t];
			if (xia > 0) {
				if (t1[t] == '1' && t1[xia] == '1') {
					if (s1[t] != s1[xia]) {
						flag = 1; // 有效替换 
//						swap(s1[t], s1[xia]);
					}
				}
				if (t2[t] == '1' && t2[xia] == '1' && !flag) {
					if (s2[t] != s2[xia]) {
						flag = 1; // 有效替换 
//						swap(s2[t], s2[xia]);
					}
				}
				if (flag == 1) {
					ans += 2;
					t = nex[xia];
				} else {
					t = xia;
				}
			} else
				break;
			flag = 0;
		}
		
		printf("%d\n", ans);
	}
}
int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	T = getin();
	while (T--) {
		// 多测清空区 
		memset(b, 0, sizeof b); 
		memset(nex, -1, sizeof nex);
		memset(t1, 0, sizeof t1);
		memset(t2, 0, sizeof t2);
		pre = 0;
		solve(); 
	}
	return 0;
}

