#include <bits/stdc++.h>

using namespace std;

int T;
int n;
string s1,s2,t1,t2;
vector<int> c1;
vector<int> c2;

int s1dfs(string this1,string this2,int left) {
    if (this1.size() == n && this2.size() == n) {
        if (left>0) return -1;
        int ans = 0;
        for (int i=0; i<n; i++) {
            if (this1[i]==this2[i]) ans++;
        }
        return ans;
    }
    string next1=this1,next2=this2;
    int n1 = this1.size(),n2 = this2.size();
    //n1 chunk
    if (n1<n) {
        next1.push_back('0');
        if (c1[n1]==-1) {
            if (left>0) return -1;
            next1[n1]=s1[n1];
            return s1dfs(next1,next2,left);
        }
        if (c1[n1]>0) left = c1[n1];
        int ans = 0;
        if (left>0) {
            next1[n1]='1';
            ans = max(ans,s1dfs(next1,next2,left-1));
        }
        next1[n1]='0';
        ans = max(ans,s1dfs(next1,next2,left));
        return ans;
    }
    if (n2==0&&left>0) return -1;
    //n2 chunk
    next2.push_back('0');
    if (c2[n2]==-1) {
        if (left>0) return -1;
        next2[n2]=s2[n2];
        return s1dfs(next1,next2,left);
    }
    if (c2[n2]>0) left = c2[n2];
    int ans = 0;
    if (left>0) {
        next2[n2]='1';
        ans = max(ans,s1dfs(next1,next2,left-1));
    }
    next2[n2]='0';
    ans = max(ans,s1dfs(next1,next2,left));
    return ans;
}

int main() {
    freopen("edit.in","r",stdin);
    freopen("edit.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> T;
    while(T>0) {
        cin >> n;
        cin >> s1 >> s2 >> t1 >> t2;
        // Solution A1
        if (n <= 10) {
            c1 = vector<int>(n,0);
            c2 = vector<int>(n,0);
            int pointed = 0;
            for (int i=0; i<n; i++) {
                if (t1[i]=='0') {
                    pointed = i+1;
                    c1[i]=-1;
                    continue;
                }
                if (s1[i]=='1') {
                    c1[pointed]++;
                }
            }
            pointed = 0;
            for (int i=0; i<n; i++) {
                if (t2[i]=='0') {
                    pointed = i+1;
                    c2[i]=-1;
                    continue;
                }
                if (s2[i]=='1') {
                    c2[pointed]++;
                }
            }
            cout << s1dfs("","",0) << endl;
            T--;
            continue;
        }
        // Solution AA
        char first;
        int success = true;
        for (int i=0; i<n; i++) {
            if (i==0) first=s1[i];
            else if (s1[i]!=first) {
                success = false;
                break;
            }
        }
        if (success) {
            int ans=0;
            for (int i=0; i<n; i++) {
                if (s1[i]==s2[i]) ans++;
            }
            cout << ans << endl;
            T--;
            continue;
        }
        // Solution AB
        if (t1 == t2) {
            int ans = 0;
            int v1=0,v2=0,len=0;
            for (int i=0; i<n; i++) {
                if (t1[i]=='0') {
                    if (v1!=0||v2!=0) {
                        ans += min(v1,v2);
                        ans += min(len-v1,len-v2);
                        v1=0;
                        v2=0;
                        len=0;
                    }
                    if (s1[i]==s2[i]) ans++;
                    continue;
                }
                len++;
                if (s1[i]=='1') v1++;
                if (s2[i]=='1') v2++;
            }
            if (v1!=0||v2!=0) {
                ans += min(v1,v2);
                ans += min(len-v1,len-v2);
                v1=0;
                v2=0;
                len=0;
            }
            cout << ans << endl;
            T--;
            continue;
        }
        // Solution AC
        int zin1 = 0,zin2=0;
        for (int i=0;i<n;i++){
            if (t1[i]=='0') zin1++;
            if (zin1 > 1) break;
            if (t2[i]=='0') zin2++;
            if (zin2 > 1) break;
        }
        if (zin1==1&&zin2==1){
            cout << "WA" << endl;
            T--;
        }
        // Solution WA
        cout << "WA" << endl;
        T--;
    }
}
