#include <iostream>
#include <fstream>
#include <cstdint>
#include <cstddef>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>

#define FILE
#define FILE_NAME "edit"

#define type using
#define fn auto
#define letmut auto
#define let auto const
#define String std::string
#define Vec std::vector

#ifdef FILE
std::ifstream in(FILE_NAME ".in");
std::ofstream out(FILE_NAME ".out");
#else
#define in std::cin
#define out std::cout
#endif // FILE

type i32 = std::int32_t;
type i64 = std::int64_t;
type u64 = std::uint64_t;
type usize = std::size_t;

letmut t = usize(0);

letmut n = usize(0);
letmut s1 = String();
letmut s2 = String();
letmut t1 = String();
letmut t2 = String();
letmut ans = usize(0);

letmut d1 = Vec<std::pair<usize, usize>>();
letmut d2 = Vec<std::pair<usize, usize>>();

fn reset_state1() -> void {
    for (let p : d1) {
        let lft = p.first;
        let rgt = p.second;
        std::sort(s1.begin() + lft, s1.begin() + rgt + 1);
    }
}

fn next_state1() -> bool {
    letmut p = d1.begin();
RESTART1:
    let lft = p->first;
    let rgt = p->second;
    if (std::next_permutation(s1.begin() + lft, s1.begin() + rgt + 1)) {
        return true;
    } else {
        ++p;
        if (p == d1.end()) {
            return false;
        }
        goto RESTART1;
    }
}

fn reset_state2() -> void {
    for (letmut p : d1) {
        let lft = p.first;
        let rgt = p.second;
        std::sort(s2.begin() + lft, s2.begin() + rgt + 1);
    }
}

fn next_state2() -> bool {
    letmut p = d2.begin();
RESTART2:
    let lft = p->first;
    let rgt = p->second;
    if (std::next_permutation(s2.begin() + lft, s2.begin() + rgt + 1)) {
        return true;
    } else {
        ++p;
        if (p == d2.end()) {
            return false;
        }
        goto RESTART2;
    }
}

fn match_ans() -> void {
    letmut res = u64(0);
    for (letmut i = usize(0); i < n; ++i) {
        if (s1[i] == s2[i]) {
            ++res;
        }
    }
    ans = std::max(ans, res);
}

fn solve1() -> void {
//	std::cerr << t1 << " " << t2;
	d1.clear();
	d2.clear();
    letmut lst_pos1 = usize(0);
    letmut lst_pos2 = usize(0);
    for (letmut i = usize(0); i < n; ++i) {
        if (t1[i] == '0') {
            if (lst_pos1 < i) {
                d1.push_back(std::make_pair(lst_pos1, i - 1));
            }
            lst_pos1 = i + 1;
        }
        if (t2[i] == '0') {
            if (lst_pos2 < i) {
                d2.push_back(std::make_pair(lst_pos2, i - 1));
            }
            lst_pos2 = i + 1;
        }
    }
    if (lst_pos1 < n) {
    	d1.push_back(std::make_pair(lst_pos1, n - 1));
	}
	if (lst_pos2 < n) {
		d2.push_back(std::make_pair(lst_pos2, n - 1));
	}
    reset_state1();
    do {
//    	std::cerr << "s1:" << s1 << "\n";
        reset_state2();
        do{
//            std::cerr << "s2:" << s2 << "\n";
            match_ans();
        }while (next_state2());
    } while (next_state1());
    out << ans << "\n";
}

fn the_same_s1() -> bool {
    for (letmut i = usize(1); i < n; ++i) {
        if (s1[i] != s1[0]) {
            return false;
        }
    }
    return true;
}

fn solve2() -> void {
    for (let c: s2) {
        if (c == s1[0]) {
            ++ans;
        }
    }
    out << ans << "\n";
}

fn solve3() -> void {
	d1.clear();
    letmut lst_pos1 = usize(0);
    t1 += '0';
    for (letmut i = usize(0); i <= n; ++i) {
        if (t1[i] == '0') {
            if (i != n && s1[i] == s2[i]) {
                ++ans;
            }
            if (lst_pos1 < i) {
                d1.push_back(std::make_pair(lst_pos1, i - 1));
            }
            letmut s10 = u64(0);
            letmut s20 = u64(0);
            for (letmut j = lst_pos1; j <= i - 1; ++j) {
                if (s1[j] == '0') {
                    ++s10;
                }
                if (s2[j] == '0') {
                    ++s20;
                }
            }
            ans += (i - lst_pos1 + std::min(s10, s20) - std::max(s10, s20));
            lst_pos1 = i + 1;
        }
    }
    out << ans << "\n";
}

fn t1_contain_single_0() -> bool {
    letmut cnt = u64(0);
    for (let c: t1) {
        if (c == '0') {
            ++cnt;
        }
    }
    return cnt == 1;
}

fn t2_contain_single_0() -> bool {
    letmut cnt = u64(0);
    for (let c: t2) {
        if (c == '0') {
            ++cnt;
        }
    }
    return cnt == 1;
}

fn solve3_ans() -> u64 {
	d1.clear();
	letmut ans = 0;
    letmut lst_pos1 = usize(0);
    t1 += '0';
    for (letmut i = usize(0); i <= n; ++i) {
        if (t1[i] == '0') {
            if (i != n && s1[i] == s2[i]) {
                ++ans;
            }
            if (lst_pos1 < i) {
                d1.push_back(std::make_pair(lst_pos1, i - 1));
            }
            letmut s10 = u64(0);
            letmut s20 = u64(0);
            for (letmut j = lst_pos1; j <= i - 1; ++j) {
                if (s1[j] == '0') {
                    ++s10;
                }
                if (s2[j] == '0') {
                    ++s20;
                }
            }
            ans += (i - lst_pos1 + std::min(s10, s20) - std::max(s10, s20));
            lst_pos1 = i + 1;
        }
    }
    return ans;
}

fn solve4() -> void {
	d1.clear();
	d2.clear();
    letmut lst_pos1 = usize(0);
    letmut lst_pos2 = usize(0);
    letmut zp1 = usize(0);
    letmut zp2 = usize(0);
    letmut cnt1 = std::make_pair(u64(0), u64(0));
    letmut cnt2 = std::make_pair(u64(0), u64(0));
    for (letmut i = usize(0); i < n; ++i) {
        if (t1[i] == '0') {
            zp1 = i;
            if (lst_pos1 < i) {
                d1.push_back(std::make_pair(lst_pos1, i - 1));
            }
            lst_pos1 = i + 1;
        }
        if (t2[i] == '0') {
            zp2 = i;
            if (lst_pos2 < i) {
                d2.push_back(std::make_pair(lst_pos2, i - 1));
            }
            lst_pos2 = i + 1;
        }
    }
    if (lst_pos1 < n) {
    	d1.push_back(std::make_pair(lst_pos1, n - 1));
	}
	if (lst_pos2 < n) {
		d2.push_back(std::make_pair(lst_pos2, n - 1));
	}
	for (letmut i = usize(0); i < zp1; ++i) {
        if (s1[i] == '0') {
            ++cnt1.first;
        }
	}
	for (letmut i = zp1 + 1; i < n; ++i) {
        if (s1[i] == '0') {
            ++cnt1.second;
        }
	}
	for (letmut i = usize(0); i < zp2; ++i) {
        if (s2[i] == '0') {
            ++cnt2.first;
        }
	}
	for (letmut i = zp2 + 1; i < n; ++i) {
        if (s2[i] == '0') {
            ++cnt2.second;
        }
	}
	letmut ps = Vec<std::pair<String, String>>(); 
	letmut ss1a = s1;
	letmut ss1b = s1;
	letmut ss2a = s2;
	letmut ss2b = s2;
    if (zp1 < zp2) {
        if (cnt2.first != 0) {
            letmut i = usize(0);
            for (; i < zp2; ++i) {
                if (s2[i] == '0') {
                    break;
                }
            }
            std::swap(ss2a[i], ss2a[zp1]);
        }
        if (zp1 - cnt2.first + 1 != 0) {
            letmut i = usize(0);
            for (; i < zp2; ++i) {
                if (s2[i] == '1') {
                    break;
                }
            }
            std::swap(ss2b[i], ss2b[zp1]);
        }
        if (cnt1.second != 0) {
            letmut i = zp1 + 1;
            for (; i < n; ++i) {
                if (s1[i] == '0') {
                    break;
                }
            }
            std::swap(ss1a[i], ss1a[zp2]);
        }
        if (n - zp1 - cnt1.second != 0) {
            letmut i = zp1 + 1;
            for (; i < n; ++i) {
                if (s1[i] == '1') {
                    break;
                }
            }
            std::swap(ss1b[i], ss1b[zp2]);
        }
    } else {
        if (cnt1.first != 0) {
            letmut i = usize(0);
            for (i = usize(0); i < zp1; ++i) {
                if (s1[i] == '0') {
                    break;
                }
            }
            std::swap(ss1a[i], ss1a[zp2]);
        }
        if (zp2 - cnt1.first + 1 != 0) {
            letmut i = usize(0);
            for (i = usize(0); i < zp1; ++i) {
                if (s1[i] == '1') {
                    break;
                }
            }
            std::swap(ss1b[i], ss1b[zp2]);
        }
        if (cnt2.second != 0) {
            letmut i = zp2 + 1;
            for (; i < n; ++i) {
                if (s2[i] == '0') {
                    break;
                }
            }
            std::swap(ss2a[i], ss2a[zp1]);
        }
        if (n - zp2 - cnt2.second != 0) {
            letmut i = zp2 + 1;
            for (; i < n; ++i) {
                if (s2[i] == '1') {
                    break;
                }
            }
            std::swap(ss2b[i], ss2b[zp1]);
        }
    }
    ps.push_back({ss1a, ss2a}); 
    ps.push_back({ss1a, ss2b});
    ps.push_back({ss1b, ss2a});
    ps.push_back({ss1b, ss2b});
    t1[zp2] = '0';
    t2[zp1] = '0';
    for (let p : ps) {
    	s1 = p.first;
    	s2 = p.second;
    	std::cerr << solve3_ans() << "\n"; 
    	ans = std::max(ans, solve3_ans());
	} 
	out << ans;
}

fn main() -> i32
{
    in >> t;
    while (t--) {
        std::puts("1");
        ans = 0;
        in >> n;
        in >> s1;
        in >> s2;
        in >> t1;
        in >> t2;
        if (n <= 10) {
            solve1();
        } else if (the_same_s1()) {
            solve2();
        } else if (t1 == t2) {
            solve3();
        } else if (t1_contain_single_0() && t2_contain_single_0()) {
            solve4();
        }
    }
    return 0;
}
