#include <bits/stdc++.h>
template<class T>
void chkmax(T &x, const T &y) {
if (x < y) x = y;
}
template<class T>
void chkmin(T &x, const T &y) {
if (x > y) x = y;
}
using ll = long long;
void mian() {
int n;
std::string s1, s2, t1, t2;
std::cin >> n >> s1 >> s2 >> t1 >> t2;
s1 += '0', s2 += '1', t1 += '0', t2 += '0';
int c1 = 0, c2 = 0, p1 = 0, p2 = 0;
auto find_next = [&](auto &s, auto &t, int i) {
int c = 0;
while (t[i] != '0') c += s[i] == '1', ++i;
return std::make_pair(i, c);
};
std::tie(p1, c1) = find_next(s1, t1, 0);
std::tie(p2, c2) = find_next(s2, t2, 0);
int ans = n + 1;
for (;;) {
if (p1 < p2) {
c1 += s1[p1] == '1';
int t = std::max(std::min(c1, c2), c2 - (p2 - p1 - 1));
ans -= std::abs(t - c1);
c2 -= t;
std::tie(p1, c1) = find_next(s1, t1, p1 + 1);
}
else if (p1 > p2) {
c2 += s2[p2] == '1';
int t = std::max(std::min(c2, c1), c1 - (p1 - p2 - 1));
ans -= std::abs(t - c2);
c1 -= t;
std::tie(p2, c2) = find_next(s2, t2, p2 + 1);
} else if (p1 == p2) {
ans -= std::abs(c1 - c2);
ans -= s1[p1] != s2[p2];
if (p1 == n) break;
std::tie(p1, c1) = find_next(s1, t1, p1 + 1);
std::tie(p2, c2) = find_next(s2, t2, p2 + 1);
}
}
std::cout << ans << '\n';
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
freopen("edit.in", "r", stdin);
freopen("edit.out", "w", stdout);
int t;
std::cin >> t;
while (t--) mian();
}