#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
char a[100005], b[100005], c[100005], d[100005];
struct segment {
    int l, r, tot;
    inline bool operator<(const segment& a) const {
        return l < a.l;
    }
};
vector<segment> va, vb;
inline int got(int x, bool pd) {
    return pd ? upper_bound(vb.begin(), vb.end(), (segment){x, 0, 0}) - vb.begin() - 1 : upper_bound(va.begin(), va.end(), (segment){x, 0, 0}) - va.begin() - 1;
}
set<int> s;
inline void recalc(int l, int r, int& ans) {
    if (l > r)
        return;
    int i = got(l, 0), j = got(l, 1), ret = min(min(va[i].tot, vb[j].tot), r - l + 1);
    va[i].tot -= ret;
    vb[j].tot -= ret;
    ans += ret;
}
int main() {
    freopen("edit.in", "r", stdin);
    freopen("edit.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while (T--) {
        va.clear();
        vb.clear();
        s.clear();
        int n;
        scanf("%d%s%s%s%s", &n, a + 1, b + 1, c + 1, d + 1);
        int lst = 0, ret = 0;
        for (int i = 1; i <= n; i++) {
            if (b[i] == '0')
                ret++;
            if (a[i] == '1')
                ret--;
        }
        c[n + 1] = d[n + 1] = '0';
        for (int i = 1; i <= n + 1; i++)
            if (c[i] == '0') {
                if (lst < i - 1)
                    va.emplace_back((segment){lst + 1, i - 1, 0});
                if (i <= n)
                    s.insert(lst = i);
            }
        lst = 0;
        for (int i = 1; i <= n + 1; i++)
            if (d[i] == '0') {
                if (lst < i - 1)
                    vb.emplace_back((segment){lst + 1, i - 1, 0});
                if (i <= n)
                    s.insert(lst = i);
            }
        int ans = 0;
        for (auto& i: va)
            for (int j = i.l; j <= i.r; j++)
                i.tot += (a[j] == '1');
        for (auto& i: vb)
            for (int j = i.l; j <= i.r; j++)
                i.tot += (b[j] == '1');
        if (s.empty()) {
            printf("%d\n", min(va[0].tot, va[1].tot) * 2 + ret);
            continue;
        }
        recalc(1, *s.begin() - 1, ans);
        for (auto it = s.begin(); ; ) {
            int i = *it;
            if (c[i] == '0' && d[i] == '0')
                ans += (a[i] == '1' && b[i] == '1');
            else if (c[i] == '0' && a[i] == '1') {
                int j = got(i, 1);
                if (vb[j].tot) {
                    vb[j].tot--;
                    ans++;
                }
            } else if (d[i] == '0' && b[i] == '1') {
                int j = got(i, 0);
                if (va[j].tot) {
                    va[j].tot--;
                    ans++;
                }
            }
            it++;
            if (it == s.end()) {
                recalc(i + 1, n, ans);
                break;
            }
            recalc(i + 1, *it - 1, ans);
        }
        printf("%d\n", ans * 2 + ret);
    }
    return 0;
}