#include <bits/stdc++.h>
#ifndef LZY_DEBUG
#define FIN "./edit.in"
#define FOUT "./edit.out"
#endif
namespace preset {
#ifdef LZY_DEBUG
template<typename T> void debug(T msg) {
std::cerr << "DEBUG: " << msg << std::endl;
}
using std::endl;
#else
template<typename T> void debug(T msg) {}
const char endl = '\n';
#endif
const char sep = ' ';
#ifdef FIN
std::ifstream cin(FIN);
#else
using std::cin;
#endif
#ifdef FOUT
std::ofstream cout(FOUT);
#else
using std::cout;
#endif
}
namespace solution {
using namespace preset;
const int N = 1.1e5;
int n;
std::string s1,s2,t1,t2;
struct node {
int f, f2o, f2y;
int o, y;
int l, r;
} p1[N], p2[N];
int p1len, p2len;
void main() {
int t;
cin >> t;
while (t--) {
int ans = 0;
int i1 = 0, i2 = 0;
p1len = p2len = 0;
cin >> n >> s1 >> s2 >> t1 >> t2;
int l1 = -1, l2 = -1;
int o1, o2, y1, y2;
for (int i = 0; i < n; i++) {
if (t1[i] == '1') {
if (l1 == -1) {
l1 = i;
o1 = y1 = 0;
}
if (s1[i] == '0') {
o1++;
} else {
y1++;
}
} else {
if (l1 != -1) {
p1[p1len++] = {0,0,0,o1, y1, l1, i - 1};
l1 = -1;
}
}
if (t2[i] == '1') {
if (l2 == -1) {
l2 = i;
o2 = y2 = 0;
}
if (s2[i] == '0') {
o2++;
} else {
y2++;
}
} else {
if (l2 != -1) {
p2[p2len++] = {0,0,0,o2, y2, l2, i - 1};
l2 = -1;
}
}
}
if (l1 != -1) {
p1[p1len++] = {0,0,0,o1, y1, l1, n - 1};
l1 = -1;
}
if (l2 != -1) {
p2[p2len++] = {0,0,0,o2, y2, l2, n - 1};
l2 = -1;
}
for (int i = 0; i < n; i++) {
if (t1[i] == '0' && t2[i] == '0') {
ans += (s1[i] == s2[i]);
} else if (t2[i] == '0') {
if (s2[i] == '0') {
if (p1[i1].o > 0) {
p1[i1].o--;
ans++;
} else p1[i1].y--;
} else {
if (p1[i1].y > 0) {
p1[i1].y--;
ans++;
} else p1[i1].o--;
}
} else if (t1[i] == '0') {
if (s1[i] == '0') {
if (p2[i2].o > 0) {
p2[i2].o--;
ans++;
} else p2[i2].y--;
} else {
if (p2[i2].y > 0) {
p2[i2].y--;
ans++;
} else p2[i2].o--;
}
} else {
p1[i1].f++;
p2[i2].f++;
}
if (p1[i1].r == i && i1 < p1len) {
int ko = std::min(p1[i1].o, p1[i1].f2o);
ans += ko;
p1[i1].o -= ko;
p1[i1].y -= p1[i1].f2o - ko;
int ky = std::min(p1[i1].y, p1[i1].f2y);
ans += ky;
p1[i1].y -= ky;
p1[i1].o -= p1[i1].f2y - ky;
p2[i2].f2o += p1[i1].o;
p2[i2].f2y += p1[i1].y;
i1++;
}
if (p2[i2].r == i && i2 < p2len) {
int ko = std::min(p2[i2].o, p2[i2].f2o);
ans += ko;
p2[i2].o -= ko;
p2[i2].y -= p2[i2].f2o - ko;
int ky = std::min(p2[i2].y, p2[i2].f2y);
ans += ky;
p2[i2].y -= ky;
p2[i2].o -= p2[i2].f2y - ky;
p1[i1].f2o += p2[i2].o;
p1[i1].f2y += p2[i2].y;
i2++;
}
}
cout << ans << endl;
}
}
}
int main() {
solution::main();
preset::cout << std::endl;
return 0;
}