#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
namespace Main {
#define int long long
#define endl '\n'
#define lson i<<1
#define rson i<<1|1
#define debug(x) cerr<<"["#x"] : " << x << endl;
#define debug2(x,y) cerr<<"["#x", "#y"] : " << x << ' ' << y << endl;
#define debug3(x,y,z) cerr<<"["#x", "#y", "#z"] : " << x << ' ' << y << ' ' << z << endl;
const int N = 1e5 + 55, MOD = 998244353, INF = 1e18;
int T, n, m, cnta, cntb, ans;
string s1, s2, t1, t2;
struct node {
int l, r, x, y;
} a[N], b[N];
void func(node &a, node &b) {
if (a.x < b.x) {
ans += a.x + b.y;
a.y -= b.x + b.y - a.x, a.x = 0;
} else if (a.y < b.y) {
ans += a.y + b.x;
a.x -= b.x + b.y - a.y, a.y = 0;
} else ans += b.x + b.y, a.x -= b.x, a.y -= b.y;
}
signed main() {
freopen("edit.in", "r", stdin);
freopen("edit.out", "w", stdout);
cin.tie(0), ios_base::sync_with_stdio(false);
cin >> T;
while (T--) {
cin >> n >> s1 >> s2 >> t1 >> t2;
s1 = "0" + s1 + "0", s2 = "0" + s2 + "0";
t1 = "0" + t1 + "0", t2 = "0" + t2 + "0";
cnta = cntb = 0;
int x0 = (s1[1] == '0'), x1 = (s1[1] == '1'), lst = 1;
for (int i = 2; i <= n; i++) {
if (t1[i - 1] == '0' || t1[i] == '0') {
a[++cnta] = {lst, i - 1, x0, x1};
x0 = x1 = 0;
}
x0 += s1[i] == '0';
x1 += s1[i] == '1';
}
a[++cnta] = {lst, n, x0, x1};
x0 = (s2[1] == '0'), x1 = (s2[1] == '1'), lst = 1;
for (int i = 2; i <= n; i++) {
if (t2[i - 1] == '0' || t2[i] == '0') {
b[++cntb] = {lst, i - 1, x0, x1};
x0 = x1 = 0;
}
x0 += s2[i] == '0';
x1 += s2[i] == '1';
}
b[++cntb] = {lst, n, x0, x1};
ans = 0;
for (int i = 1, j = 1; i <= cnta && j <= cntb; ) {
if (a[i].r >= b[j].r) {
func(a[i], b[j]);
j++;
} else {
func(b[j], a[i]);
i++;
}
}
cout << ans << endl;
}
return 0;
}
}
signed main() {
Main::main();
return 0;
}