#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
char s[N], t[N], vs[N], vt[N];
int calc(int l, int r){
    if(l > r) return 0;
    int s0 = 0, s1 = 0, t0 = 0, t1 = 0;
    for(int i = l;i <= r;i++){
        if(s[i] == '0') s0++;
        else s1++;
        if(t[i] == '0') t0++;
        else t1++;
    }
    return min(s0, t0) + min(s1, t1);
}
int n, ans, gt;

void sol(){
    ans = 0;
    cin >> n;
    cin >> s + 1 >> t + 1;
    cin >> vs + 1 >> vt + 1;
    bool fa = 1;
    for(int i = 1;i < n;i++) if(s[i] != s[i + 1]) fa = 0;
    if(fa){
        for(int i = 1;i <= n;i++) if(s[i] == t[i]) ans++;
        cout << ans << endl;
        return ;
    }
    bool fb = 1;
    for(int i = 1;i <= n;i++) if(vs[i] != vt[i]) fb = 0;
    if(fb){
        vector<pair<int, int>> vec;
        int lstp = 0;
        for(int i = 1;i <= n;i++){
            if(vs[i] == '0' && vt[i] == '0'){
                ans += (s[i] == t[i]);
                if(lstp + 1 <= i - 1) vec.push_back({lstp + 1, i - 1});
                lstp = i;
            }
        }
        vec.push_back({lstp + 1, n});
        for(pair<int, int> seg: vec){
            int l = seg.first, r = seg.second;
            ans += calc(l, r);
        }
        cout << ans << endl;
        return ;
    }
    int p1 = 0, p2 = 0;
    for(int i = 1;i <= n;i++){
        if(vs[i] == '0') p1 = i;
        if(vt[i] == '0') p2 = i;
    }
    if(p1 == p2){
        if(s[p1] == t[p1]) ans++;
        ans += calc(1, p1 - 1) + calc(p1 + 1, n);
        cout << ans << endl;
        return ;
    }
    int sp0 = 0, sp1 = 0, sf0 = 0, sf1 = 0;
    int tp0 = 0, tp1 = 0, tf0 = 0, tf1 = 0;
    for(int i = 1;i <= p1 - 1;i++){
        if(s[i] == '0') sp0++;
        else sp1++;
    }
    for(int i = p1 + 1;i <= n;i++){
        if(s[i] == '0') sf0++;
        else sf1++;
    }
    for(int i = 1;i <= p2 - 1;i++){
        if(t[i] == '0') tp0++;
        else tp1++;
    }
    for(int i = p2 + 1;i <= n;i++){
        if(t[i] == '0') tf0++;
        else tf1++;
    }
    if(p1 > p2){
        swap(p1, p2);
        swap(sp0, tp0);
        swap(sp1, tp1);
        swap(sf0, tf0);
        swap(sf1, tf1);
        for(int i = 1;i <= n;i++) swap(s[i], t[i]);
    }
    gt = min(sp0, tp0);
    sp0 -= gt, tp0 -= gt;
    ans += gt;

    gt = min(sp1, tp1);
    ans += gt;
    sp1 -= gt, tp1 -= gt;

    gt = min(sf0, tf0);
    sf0 -= gt, tf0 -= gt;
    ans += gt;

    gt =  min(sf1, tf1);
    sf1 -= gt, tf1 -= gt;
    ans += gt;
    if(s[p1] == '1'){
        gt = min(tp1, 1);
        ans += gt;
        tp1 -= gt;
    }
    else{
        gt = min(tp0, 1);
        ans += gt;
        tp0 -= gt;
    }
    if(t[p2] == '1'){
        gt = min(sf1, 1);
        ans += gt;
        sf1 -= gt;
    }
    else{
        gt = min(sf0, 1);
        ans += gt;
        sf0 -= gt;
    }
    ans += min(min(sf0, tp0) + min(sf1, tp1), p2 - p1 - 1);
    cout << ans << endl;
}
int main(){
    freopen("edit.in","r",stdin);
    freopen("edit.out","w",stdout);
    int cas;cin >> cas;
    while(cas--) sol();
    return 0;
}