#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 1e5 + 10;
int T, n, cnt[2], belong[2][N];
char s[2][N], t[2][N];
struct BLOCK {
    int c0, c1, l, r;
} a[2][N];
void init(int x) {
    int c0 = 0, c1 = 0;
    for (int i = 1; i <= n; i++) {
        if (t[x][i] == '0') {
            if (c0 or c1) {
                int l = i - c0 - c1, r = i - 1;
                a[x][++cnt[x]] = {c0, c1, l, r};
                for (int j = l; j <= r; j++)
                    belong[x][j] = cnt[x];
            }
            c0 = c1 = 0;
            a[x][++cnt[x]] = {s[x][i] == '0', s[x][i] == '1', i, i};
            belong[x][i] = cnt[x];
        } else {
            if (s[x][i] == '0')
                c0++;
            else
                c1++;
        }
    }
    if (c0 or c1) {
        int l = n - c0 - c1 + 1, r = n;
        a[x][++cnt[x]] = {c0, c1, l, r};
        for (int j = l; j <= r; j++)
            belong[x][j] = cnt[x];
    }
}
void clear() {
    for (int i = 0; i < 2; i++) {
        for (int j = 1; j <= n; j++)
            belong[i][j] = 0;
        for (int j = 1; j <= cnt[i]; j++)
            a[i][j] = {0, 0, 0, 0};
        cnt[i] = 0;
    }
}
void solve() {
    cin >> n;
    cin >> (s[0] + 1) >> (s[1] + 1) >> (t[0] + 1) >> (t[1] + 1);
    init(0), init(1);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[0][belong[0][i]].c0 and a[1][belong[1][i]].c0) {
            a[0][belong[0][i]].c0--, a[1][belong[1][i]].c0--;
            ans++;
        } else if (a[0][belong[0][i]].c1 and a[1][belong[1][i]].c1) {
            a[0][belong[0][i]].c1--, a[1][belong[1][i]].c1--;
            ans++;
        }
    }
    cout << ans << "\n";
    clear();
}
signed main() {
    freopen("edit.in", "r", stdin);
    freopen("edit.out", "w", stdout);
    IOS;
    cin >> T;
    while (T--)
        solve();
    return 0;
}