#include<bits/stdc++.h>
// #define DEBUG
const int N = 2e5 + 10;
char s[3][N], t[3][N];
int n;
struct block{
	int l, r;
	int b[2];
	block(){}
	block(int ll, int rr, int aa, int bb){
		l = ll;
		r = rr;
		b[0] = aa;
		b[1] = bb;
	}
};
#define f(x) (x == 1 ? 2 : 1)
void solve(){
	scanf("%d", &n);
	scanf("%s", s[1] + 1);
	scanf("%s", s[2] + 1);
	scanf("%s", t[1] + 1);
	scanf("%s", t[2] + 1);
	std::vector<block> v[3];
	int pre = 1;
	int a = 0, b = 0;
	for(int i = 1 ; i <= n ; i++){
		if(t[1][i] == '0'){
			v[1].push_back(block(pre, i, a, b));
			pre = i + 1;
			a = 0, b = 0;
		}
		else{
			a += s[1][i] == '0';
			b += s[1][i] == '1';
		}
	}
	if(pre != n + 1)
		v[1].push_back(block(pre, n + 1, a, b));
	pre = 1, a = b = 0;
	for(int i = 1 ; i <= n ; i++){
		if(t[2][i] == '0'){
			v[2].push_back(block(pre, i, a, b));
			pre = i + 1;
			a = 0, b = 0;
		}
		else{
			a += s[2][i] == '0';
			b += s[2][i] == '1';
		}
	}
	if(pre != n + 1)
		v[2].push_back(block(pre, n + 1, a, b));
	int idx[3] = {0, 0, 0};
	int now = v[1][0].r < v[2][0].r ? 2 : 1;
	int ans = 0;
	a = v[now][0].b[0], b = v[now][0].b[1];
	int aa = v[f(now)][0].b[0], bb = v[f(now)][0].b[1];
	while(1){
		int x = f(now);
		if(v[now][idx[now]].r == v[x][idx[x]].r){
			ans += std::min(aa, a);
			ans += std::min(bb, b);
			if(v[now][idx[now]].r != n + 1)
				ans += s[now][v[now][idx[now]].r] == s[x][v[x][idx[x]].r];
			if(idx[now] == v[now].size() - 1 && idx[x] == v[x].size() - 1)
				break;
			idx[now]++;
			idx[x]++;
			a = v[now][idx[now]].b[0];
			b = v[now][idx[now]].b[1];
			aa = v[x][idx[x]].b[0];
			bb = v[x][idx[x]].b[1];
			continue;
		}
		if(v[now][idx[now]].r < v[x][idx[x]].r){
			std::swap(now, x);
			std::swap(a, aa);
			std::swap(b, bb);
		}
		if(s[x][v[x][idx[x]].r] != n + 1){
			aa += s[x][v[x][idx[x]].r] == '0';
			bb += s[x][v[x][idx[x]].r] == '1';
		}
		int minna = std::min(a, aa);
		int minnb = std::min(b, bb);
		a -= minna;
		b -= minnb;
		aa -= minna;
		bb -= minnb;
		if(aa + bb){
			if(a == 0) b -= aa + bb;
			else a -= aa + bb;
		}
		aa = bb = 0;
		ans += minna + minnb;
		if(idx[now] == v[now].size() - 1 && idx[x] == v[x].size() - 1)
			break;
		idx[x]++;
		aa = v[x][idx[x]].b[0];
		bb = v[x][idx[x]].b[1];
	}
	printf("%d\n", ans);
}
int main(){
	#ifndef DEBUG
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	#endif
	int t;
	scanf("%d", &t);
	while(t--)
		solve();
	return 0;
}