#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void SetIO(string s = "")
{
    if (s != "")
    {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);
}

const int N = 1e5 + 5;

struct Node{
    int l, r;
}tmp1[N], tmp2[N];

int T, n, tot;
string a, b, s, t;

signed main()
{
    SetIO("edit");
    cin >> T;
    while(T--)
    {
        int tot1 = 0, tot2 = 0;
        cin >> n;
        cin >> s >> t >> a >> b;
        a = " " + a;
        b = " " + b;
        s = " " + s;
        t = " " + t;
        for (int i = 1; i <= n; i++)
        {
            if (i != 1 && a[i] == '1' && a[i - 1] == '1')
                tmp1[tot1].r = i;
            else
                tmp1[++tot1] = Node{i, i};
        }
        for (int i = 1; i <= n; i++)
        {
            if (i != 1 && b[i] == '1' && b[i - 1] == '1')
                tmp2[tot2].r = i;
            else
                tmp2[++tot2] = Node{i, i};
        }
        int ans = 0, nums0 = 0, nums1 = 0, numt0 = 0, numt1 = 0;
        for (int i = 1, j = 0, k = 0; i <= n; i++)
        {
            if (i > tmp1[j].r)
            {
                j++;
                nums0 = nums1 = 0;
                for (int p = tmp1[j].l; p <= tmp1[j].r; p++)
                {
                    if (s[p] == '0')
                        nums0++;
                    else
                        nums1++;
                }
            }
            if (i > tmp2[k].r)
            {
                k++;
                numt0 = numt1 = 0;
                for (int p = tmp2[k].l; p <= tmp2[k].r; p++)
                {
                    if (t[p] == '0')
                        numt0++;
                    else
                        numt1++;
                }
            }
            if (nums0 && numt0)
                nums0--, numt0--;
            else if (nums1 && numt1)
                nums1--, numt1--;
            else
                ans++;
        }
        cout << n - ans << '\n';
    }
}