#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <cstring>
#ifdef LNYXJ
#include <cassert>
#else
#define assert(x)
#endif
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define xx first
#define yy second
#define FILENAME "edit"
#define openfile(file) \
freopen(file".in", "r", stdin); \
freopen(file".out", "w", stdout);
using namespace std;
const int N = 1e5 + 5, mod = 998244353;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long long ll;
inline void Add(int& x, int y) { ((x += y) >= mod) && (x -= mod); }
inline int ksm(int b, int e) {
int res = 1;
while (e) {
(e & 1) && (res = 1ll * res * b % mod);
b = 1ll * b * b % mod;
e >>= 1;
}
return res;
}
int n;
string s1, s2, t1, t2;
int ans;
void calc(pii& a, pii& b, int lim) {
const int w1 = min(min(a.xx, b.xx), lim), w2 = min(min(a.yy, b.yy), lim);
ans += w1 + w2;
a.xx -= w1; a.yy -= w2;
b.xx -= w1; b.yy -= w2;
}
void solve() {
cin >> n;
cin >> s1 >> s2 >> t1 >> t2;
static int c1[2], c2[2], las1[2], las2[2];
memset(c1, 0, sizeof c1);
memset(c2, 0, sizeof c2);
static pii w1[N], w2[N];
int tt1 = 0, tt2 = 0;
for (int i = 0; i < n; ++ i) {
if (t1[i] == '0') {
if (c1[0] || c1[1]) w1[++ tt1] = {c1[0], c1[1]};
c1[0] = c1[1] = 0;
if (s1[i] == '0') w1[++ tt1] = {1, 0};
else w1[++ tt1] = {0, 1};
} else ++ c1[s1[i] - '0'];
}
if (c1[0] || c1[1]) w1[++ tt1] = {c1[0], c1[1]};
for (int i = 0; i < n; ++ i) {
if (t2[i] == '0') {
if (c2[0] || c2[1]) w2[++ tt2] = {c2[0], c2[1]};
c2[0] = c2[1] = 0;
if (s2[i] == '0') w2[++ tt2] = {1, 0};
else w2[++ tt2] = {0, 1};
} else ++ c2[s2[i] - '0'];
}
if (c2[0] || c2[1]) w2[++ tt2] = {c2[0], c2[1]};
t1 += '0'; t2 += '0';
int cur1 = 1, cur2 = 1;
ans = 0;
for (int i = 0, las = -1; i < n; ++ i) {
if (t1[i] == '0' || t1[i + 1] == '0') {
calc(w1[cur1], w2[cur2], i - las);
w1[cur1] = {0, 0};
las = i; ++ cur1;
}
if (t2[i] == '0' || t2[i + 1] == '0') {
calc(w2[cur2], w1[cur1], i - las);
w2[cur2] = {0, 0};
las = i; ++ cur2;
}
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef LNYXJ
openfile(FILENAME)
#endif
int T = 1;
cin >> T;
while (T --) solve();
return 0;
}