#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
constexpr int N = 100010, MOD = 1000000007;
int T;
int n;
string s1, s2, sq1, sq2;
signed main()
{
    freopen("edit.in", "r", stdin);
    freopen("edit.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> T;
    while (T--)
    {
        cin >> n;
        cin >> s1 >> s2 >> sq1 >> sq2;
        char p = s1.front();
        bool flag = true;
        for (auto it : s1)
        {
            if (it != p)
            {
                flag = false;
                break;
            }
        }
        if (flag == true)
        {
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (s2[i] == s1[i])
                {
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
        else
        {
            vector<int> v1, v2;
            v1.push_back(-1);
            v2.push_back(-1);
            for (int i = 0; i < n; i++)
            {
                if (sq1[i] == '0')
                {
                    v1.push_back(i);
                }
                if (sq2[i] == '0')
                {
                    v2.push_back(i);
                }
            }
            v1.push_back(n);
            v2.push_back(n);
            for (int i = 1; i < v1.size(); i++)
            {
                sort(s1.begin() + v1[i - 1] + 1, s1.begin() + v1[i]);
            }
            for (int i = 1; i < v2.size(); i++)
            {
                sort(s2.begin() + v2[i - 1] + 1, s2.begin() + v2[i]);
            }
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (s2[i] == s1[i])
                {
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }

    return 0;
}
/*
1
10
1011101010
1000010001
1111101111
1111101111

*/