#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
inline int read(){
	int ans = 0, flg = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-') flg = -flg;
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		ans = ans * 10 + c - '0';
		c = getchar();
	}
	return ans * flg;
}
int n;
char a[maxn], b[maxn];
char tmp1[maxn], tmp2[maxn];
bool flag1[maxn], flag2[maxn];
struct B{
	int l, r, cnt0, cnt1;
} block1[maxn], block2[maxn];
int tot1, tot2;
void init(){
	tot1 = tot2 = 0;
	for(int i = 0; i < maxn; i++){
		a[i] = b[i] = '0';
		tmp1[i] = tmp2[i] = '0';
		flag1[i] = flag2[i] = 1;
		block1[i].l = block1[i].r = block1[i].cnt0 = block1[i].cnt1 = 0;
		block2[i].l = block2[i].r = block2[i].cnt0 = block2[i].cnt1 = 0;
	}
}
void solve1(){
	int l = 1, r = 0, cnt0 = 0, cnt1 = 0;
	for(int i = 1; i <= n; i++){
		flag1[i] = tmp1[i] - '0';
		if(flag1[i] == 1){
//			cnt0 += (a[i] == '0');
//			cnt1 += (a[i] == '1');
			if(a[i] == '0'){
				cnt0++; 
			}else{
				cnt1++;
			}
			r++;
		}else{
			if(r > 0){
				block1[++tot1] = {l, r, cnt0, cnt1};
			}
			block1[++tot1] = {i, i, ((a[i] == '0') ? 1 : 0), ((a[i] == '1') ? 1 : 0)};
			l = i + 1, r = i, cnt0 = 0, cnt1 = 0;
		}
	}
	if(l <= n && r <= n){
		block1[++tot1] = {l, r, cnt0, cnt1};
	}
}
void solve2(){
	int l = 1, r = 0, cnt0 = 0, cnt1 = 0;
	for(int i = 1; i <= n; i++){
		flag2[i] = tmp2[i] - '0';
		if(flag2[i] == 1){
//			cnt0 += (b[i] == '0');
//			cnt1 += (b[i] == '1');
			if(b[i] == '0'){
				cnt0++; 
			}else{
				cnt1++;
			}
			r++;
		}else{
			if(r > 0){
				block2[++tot2] = {l, r, cnt0, cnt1};
			}
			block2[++tot2] = {i, i, (b[i] == '0'), (b[i] == '1')};
			l = i + 1, r = i, cnt0 = 0, cnt1 = 0;
		}
	}
	if(l <= n && r <= n){
		block2[++tot2] = {l, r, cnt0, cnt1};
	}
}
bool checkA(){
	for(int i = 2; i <= n; i++){
		if(a[i] != a[i - 1]){
			return 0;
		}
	}
	return 1;
}
bool checkC(){
	int C1 = 0, C2 = 0;
	for(int i = 1; i <= n; i++){
		C1 += (tmp1[i] == '0');
		C2 += (tmp2[i] == '0');
	}
	return ((C1 == 1) && (C2 == 1));
}
signed main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T = read();
	while(T--){
		int ans = 0;
		n = read();
		init();
		cin >> (a + 1) >> (b + 1);
		cin >> (tmp1 + 1) >> (tmp2 + 1);
		if(checkA()){
			int cnt = 0;
			for(int i = 1; i <= n; i++){
				cnt += (b[i] == a[i]);
			}
			cout << cnt << "\n";
			continue;
		}
		solve1();
		solve2();
		int id = 1;
		for(int i = 1; i <= tot1; i++){
//			printf("(begin)i:%d id:%d\n", i, id);
			int L1 = block1[i].l, R1 = block1[i].r, cnt0 = block1[i].cnt0, cnt1 = block1[i].cnt1;
			int sum0 = 0, sum1 = 0;
			while(id <= tot2 && block2[id].r < R1){
				sum0 += block2[id].cnt0;
				sum1 += block2[id].cnt1;
//				printf("id:%d sum0:%d sum1:%d\n", id, sum0, sum1);
				id++;
			}
			
			id--;
			ans += max(0ll, min(sum0, cnt0));
			ans += max(0ll, min(sum1, cnt1));
//			printf("i:%d ans:%d\n", i, ans);
			int rest0 = cnt0, rest1 = cnt1;
			if(cnt0 >= sum0 && cnt1 >= sum1){
				rest0 = cnt0 - sum0;
				rest1 = cnt1 - sum1;
			}else if(cnt1 < sum1){ 
				int len = block2[id].r - L1 + 1;
				rest1 = 0;
				rest0 = cnt0 - (len - cnt1);
			}else if(cnt0 < sum0){
				int len = block2[id].r - L1 + 1;
				rest0 = 0;
				rest1 = cnt1 - (len - cnt0);
			}
//			cout << i << " " << rest0 << " " << rest1 << "\n";
			id++;
			if(id > tot2) break;
//			if(rest0 + rest1 > block2[id].cnt0 + block2[id].cnt1) printf("id:%d i:%d rest0:%d rest1:%d cnt0:%d cnt1:%d\n", id, i, rest0, rest1, block2[id].cnt0, block2[id].cnt1);
			if(rest0 <= block2[id].cnt0 && rest1 <= block2[id].cnt1){
				ans += rest0 + rest1;
				block2[id].cnt0 -= rest0;
				block2[id].cnt1 -= rest1;
			}else if(rest1 <= block2[i].cnt1){
				ans += block2[id].cnt0 + rest1;
				int len = R1 - block2[id].l + 1;
//				printf("id:%d i:%d len:%d\n", id, i, len);
				block2[id].cnt1 -= (len - block2[id].cnt0);
				block2[id].cnt0 = 0;
			}else if(rest0 <= block2[i].cnt0){
				ans += block2[id].cnt1 + rest0;
				int len = R1 - block2[id].l + 1;
//				printf("id:%d i:%d len:%d\n", id, i, len);
				block2[id].cnt0 -= (len - block2[id].cnt1);
				block2[id].cnt1 = 0;
			}
			if(block2[id].r == R1){
				id++;
			}else{
				block2[id].l = R1 + 1;
			}
//			printf("i:%d ans:%d\n", i, ans);
		}
		cout << ans << "\n";
	}
	return 0;
}
