#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <queue>
#include <utility>
#include <random>
#define fi first
#define se second
using namespace std;
typedef long long LL;

template <typename Tp> inline void read(Tp& x) {
    char ch; bool op = 0; x = 0;
    do ch = getchar(), op |= ch == '-'; while (ch < '0' || ch > '9');
    do x = (x<<3)+(x<<1)+(ch&15), ch = getchar(); while (ch >= '0' && ch <= '9');
    if (op) x = -x;
}

inline int read01() {
    char ch;
    do ch = getchar(); while (ch != '0' && ch != '1');
    return ch ^ 48;
}

template <typename Tp> inline void write(Tp x, char ed='\n') {
    static int arr[50]; int tp = 0;
    do arr[++tp] = x % 10, x /= 10; while (x);
    for (; tp; --tp) putchar(arr[tp] | 48);
    putchar(ed);
}

const int mod = 1e9+7;
inline int fplus(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int Fplus(int& x, int y) { return x = fplus(x, y); }
inline int fminus(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
inline int Fminus(int& x, int y) { return x = fminus(x, y); }

bool Mst;
int n;
const int MAXN = 1e5+5;
struct Itv {
    int l, r, cnt[2];
    Itv(int _l = 0, int _r = 0) {
        l = _l, r = _r, cnt[0] = cnt[1] = 0;
    }
    operator bool() { return cnt[0] || cnt[1]; }
};
int calc(Itv& x, Itv& y) {
    int c0 = min(x.cnt[0], y.cnt[0]), c1 = min(x.cnt[1], y.cnt[1]);
    x.cnt[0] -= c0, y.cnt[0] -= c0, x.cnt[1] -= c1, y.cnt[1] -= c1;
    if (x.cnt[0] && y.cnt[1]) {
        int val = min(x.cnt[0], y.cnt[1]);
        x.cnt[0] -= val, y.cnt[1] -= val;
    }
    if (x.cnt[1] && y.cnt[0]) {
        int val = min(x.cnt[1], y.cnt[0]);
        x.cnt[1] -= val, y.cnt[0] -= val;
    }
    assert(!x || !y);
    return c0 + c1;
}

struct Data {
    bool val[MAXN], mdf[MAXN];
    int bel[MAXN], tot;
    Itv itv[MAXN];
    void init() {
        tot = 0;
        for (int i = 1; i <= n; ++i) {
            if (mdf[i]) {
                if (!mdf[i-1]) itv[++tot] = Itv(i, i);
                bel[i] = tot;
                itv[bel[i]].r = i;
                ++itv[bel[i]].cnt[val[i]];
            } else bel[i] = 0;
        }
    }
} A, B;
int ans;

bool Med;


int main() {
    freopen("edit.in", "r", stdin);
    freopen("edit.out", "w", stdout);
    fprintf(stderr, "%.3lf\n", (&Mst - &Med) / 1048576.);
    int T; read(T);
    while (T--) {
        read(n);
        for (int i = 1; i <= n; ++i) A.val[i] = read01();
        for (int i = 1; i <= n; ++i) B.val[i] = read01();
        for (int i = 1; i <= n; ++i) A.mdf[i] = read01();
        for (int i = 1; i <= n; ++i) B.mdf[i] = read01();
        ans = 0;
        A.init(), B.init();
        for (int i = 1; i <= n; ++i) {
            if (!A.mdf[i] && !B.mdf[i]) {
                ans += A.val[i] == B.val[i];
            } else if (!B.mdf[i]) {
                int bel = A.bel[i], v = B.val[i];
                if (A.itv[bel].cnt[v]) ++ans, --A.itv[bel].cnt[v];
                else --A.itv[bel].cnt[v^1];
            } else if (!A.mdf[i]) {
                int bel = B.bel[i], v = A.val[i];
                if (B.itv[bel].cnt[v]) ++ans, --B.itv[bel].cnt[v];
                else --B.itv[bel].cnt[v^1];
            }
        }
        for (int p = 1, q = 1; p <= A.tot || q <= B.tot; p += !A.itv[p], q += !B.itv[q])
            ans += calc(A.itv[p], B.itv[q]);
        write(ans);
    }
    return 0;
}

