#include <cstdio>
using namespace std;
const int maxn = 100010;
char s[2][maxn] = {0}, a[2][maxn] = {0};
int c[2][maxn] = {0};
int min (int a, int b) {
return (a < b) ? a : b;
}
int n, res = 0;
void swap (char &x, char &y) {
char t = x;
x = y;
y = t;
}
void dfs (int now) {
if (now == n) {
int cnt = 0;
for (int i = 0; i < n; i ++) {
if (s[0][i] == s[1][i]) {
cnt ++;
}
}
if (res < cnt) {
res = cnt;
}
return;
}
dfs (now + 1);
if (a[0][now] == '1' && a[0][now + 1] == '1') {
swap(s[0][now], s[0][now + 1]);
dfs(now + 1);
}
if (a[1][now] == '1' && a[1][now + 1] == '1') {
swap(s[1][now], s[1][now + 1]);
dfs(now + 1);
}
if (a[0][now] == '1' && a[0][now + 1] == '1') {
swap(s[0][now], s[0][now + 1]);
dfs(now + 1);
}
if (a[1][now] == '1' && a[1][now + 1] == '1') {
swap(s[1][now], s[1][now + 1]);
}
}
int fa[maxn << 1] = {0}, lf[maxn << 1] = {0}, rg[maxn << 1] = {0};
int buc[maxn << 1][2] = {0};
int find (int x) {
return (fa[x] == x) ? x : (fa[x] = find(fa[x]));
}
int max (int a, int b) {
return a > b ? a : b;
}
void solve5() {
for (int i = 0; i < 2 * n; i ++) {
fa[i] = i;
lf[i] = (i > n) ? (i - n) : i;
rg[i] = (i > n) ? (i - n) : i;
buc[i][0] = 0;
buc[i][1] = 0;
}
for (int i = 0; i < n; ) {
if (a[0][i] == '0') {
buc[i][s[0][i] - '0'] ++;
i ++;
continue;
}
int j = i;
while (a[0][j] == '1' && j < n) {
fa[j] = i;
buc[i][s[0][j] - '0'] ++;
j ++;
}
rg[i] = j - 1;
i = j;
}
for (int i = 0; i < n; ) {
if (a[1][i] == '0') {
buc[i + n][s[1][i] - '0'] ++;
i ++;
continue;
}
int j = i;
while (a[1][j] == '1' && j < n) {
fa[j + n] = i + n;
buc[i + n][s[1][j] - '0'] ++;
j ++;
}
rg[i + n] = j - 1;
i = j;
}
for (int i = 0; i < n; i ++) {
if (a[0][i] == '0') {
if (a[1][i] == '0') {
res += ((s[0][i] == s[1][i]) ? 1 : 0);
}
else {
int aa = find(i + n);
if (s[0][i] == '0' && buc[aa][0] != 0) {
res ++;
buc[i][0] --;
buc[aa][0] --;
}
else if (s[0][i] == '1' && buc[aa][1] != 0) {
res ++;
buc[i][1] --;
buc[aa][1] --;
}
}
}
else {
if (a[1][i] == '0') {
int aa = find(i);
if (s[1][i] == '0' && buc[aa][0] != 0) {
res ++;
buc[aa][0] --;
buc[i + n][0] --;
}
else if (s[1][i] == '1' && buc[aa][1] != 0) {
res ++;
buc[aa][1] --;
buc[i + n][1] --;
}
}
else {
int aa = find(i), bb = find(i + n);
int t = min(buc[aa][0], buc[bb][0]), t_ = min(buc[aa][1], buc[bb][1]);
res += t + t_;
buc[aa][0] -= t;
buc[bb][0] -= t;
buc[aa][1] -= t_;
buc[bb][1] -= t_;
}
}
}
printf("%d\n", res);
}
int main () {
freopen("edit.in", "r", stdin);
freopen("edit.out", "w", stdout);
int _;
scanf("%d", &_);
while (_ --) {
res = 0;
scanf("%d", &n);
scanf("%s", s[0]);
scanf("%s", s[1]);
scanf("%s", a[0]);
scanf("%s", a[1]);
bool okA = true;
for (int i = 1; i < n; i ++) {
if (s[0][0] != s[0][i]) {
okA = false;
}
}
bool okB = true;
for (int i = 0; i < n; i ++) {
if (a[0][i] != a[1][i]) {
okB = false;
}
}
int cnt00 = 0, cnt01 = 0;
for (int i = 0; i < n; i ++) {
if (a[0][i] == '0') {
cnt00 ++;
}
if (a[1][i] == '0') {
cnt01 ++;
}
}
if (n <= 10) {
dfs(0);
printf("%d\n", res);
}
else if (okA) {
int cnt = 0;
for (int i = 0; i < n; i ++) {
if (s[0][i] == s[1][i]) {
cnt ++;
}
}
printf("%d\n", cnt);
}
else if (okB) {
for (int i = 0; i < n;) {
if (a[0][i] == '0') {
res += (s[0][i] == s[1][i]) ? 1 : 0;
i ++;
continue;
}
int j = i, cnt1 = 0, cnt2 = 0;
while (a[0][j] == '1') {
cnt1 += (s[0][j] - '0');
cnt2 += (s[1][j] - '0');
j ++;
}
res += min(cnt1, cnt2) + min(j - i - cnt1, j - i - cnt2);
i = j;
}
printf("%d\n", res);
}
else if (cnt00 == 1 && cnt01 == 1) {
int cnt0[4] = {0}, cnt1[4] = {0};
int i = 0;
for (; i < n; i ++) {
cnt0[0] += (s[0][i] == '0') ? 1 : 0;
cnt1[0] += (s[0][i] - '0');
if (a[0][i] == '0') {
break;
}
}
for (int k = i + 1; k < n; k ++) {
cnt0[1] += (s[0][k] == '0') ? 1 : 0;
cnt1[1] += (s[0][k] - '0');
}
int j = 0;
for (; j < n; j ++) {
if (a[1][j] == '0') {
break;
}
cnt0[2] += (s[1][j] == '0') ? 1 : 0;
cnt1[2] += (s[1][j] - '0');
}
for (int k = j; k < n; k ++) {
cnt0[3] += (s[1][k] == '0') ? 1 : 0;
cnt1[3] += (s[1][k] - '0');
}
int t = min(cnt0[0], cnt0[2]), t_ = min(cnt1[0], cnt1[2]);
res += t + t_;
cnt0[0] -= t;
cnt0[2] -= t;
cnt1[0] -= t_;
cnt1[2] -= t_;
t = min(cnt0[1], cnt0[3]), t_ = min(cnt1[1], cnt1[3]);
res += t + t_;
cnt0[1] -= t;
cnt0[3] -= t;
cnt1[1] -= t_;
cnt1[3] -= t_;
if (i < j) {
t = min(cnt0[1], cnt0[2]), t_ = min(cnt1[1], cnt1[2]);
res += (t + t_ > j - i - 1) ? (j - i - 1) : (t + t_);
}
else {
t = min(cnt0[0], cnt0[3]), t_ = min(cnt1[0], cnt1[3]);
res += (t + t_ > i - j - 1) ? (i - j - 1) : (t + t_);
}
printf("%d\n", res);
}
else {
solve5();
}
}
return 0;
}