#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <random>
#include <chrono>
#include <ctime>
#include <numeric>
typedef long long ll;
typedef double lf;
typedef unsigned long long ull;
namespace FastIO
{
const int MAXSIZE = (1 << 20);
char buf[MAXSIZE], *p1, *p2;
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? EOF : *p1++)
template <typename T>
inline void Read(T &x)
{
x = 0; char ch = gc; bool f = 0;
while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = gc; }
while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gc;
if (f) x = -x;
}
}
using FastIO::Read;
using namespace std;
const int MAXN = 1e5 + 10;
int n;
char s[2][MAXN], t[2][MAXN];
int st1[MAXN], st2[MAXN], top1, top2;
int cnt[2][2], ans;
int main()
{
freopen("edit.in", "r", stdin);
freopen("edit.out", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--)
{
cin >> n >> s[0] + 1 >> s[1] + 1 >> t[0] + 1 >> t[1] + 1;
top1 = 0;
for (int i = 1; i <= n; i++)
if (t[0][i] == '0') st1[++top1] = i;
top2 = 0;
for (int i = 1; i <= n; i++)
if (t[1][i] == '0') st2[++top2] = i;
st1[++top1] = st2[++top2] = n + 1, s[0][n + 1] = '0', s[1][n + 1] = '1';
memset(cnt, 0, sizeof(cnt));
ans = 0;
int a = 1, b = 1;
for (int i = 1, j = 1; i <= top1 || j <= top2;)
{
if (st1[i] == st2[j])
{
while (a < st1[i]) cnt[0][s[0][a] - '0']++, a++;
while (b < st2[j]) cnt[1][s[1][b] - '0']++, b++;
ans += min(cnt[0][0], cnt[1][0]) + min(cnt[0][1], cnt[1][1]);
memset(cnt, 0, sizeof(cnt));
ans += (s[0][st1[i]] == s[1][st2[j]]), a++, b++;
i++, j++;
}
else if (st1[i] < st2[j])
{
while (a <= st1[i]) cnt[0][s[0][a] - '0']++, a++;
while (b < st2[j]) cnt[1][s[1][b] - '0']++, b++;
int x = min(cnt[0][0], cnt[1][0]), y = min(cnt[0][1], cnt[1][1]);
cnt[1][0] -= cnt[0][0], cnt[1][1] -= cnt[0][1], cnt[0][0] = cnt[0][1] = 0;
ans += x + y;
if (cnt[1][0] < 0) cnt[1][1] += cnt[1][0], cnt[1][0] = 0;
if (cnt[1][1] < 0) cnt[1][0] += cnt[1][1], cnt[1][1] = 0;
i++;
}
else
{
while (a < st1[i]) cnt[0][s[0][a] - '0']++, a++;
while (b <= st2[j]) cnt[1][s[1][b] - '0']++, b++;
int x = min(cnt[0][0], cnt[1][0]), y = min(cnt[0][1], cnt[1][1]);
cnt[0][0] -= cnt[1][0], cnt[0][1] -= cnt[1][1], cnt[1][0] = cnt[1][1] = 0;
ans += x + y;
if (cnt[0][0] < 0) cnt[0][1] += cnt[0][0], cnt[0][0] = 0;
if (cnt[0][1] < 0) cnt[0][0] += cnt[0][1], cnt[0][1] = 0;
j++;
}
}
cout << ans << '\n';
}
return 0;
}