#include<bits/stdc++.h>
#define fup(i, bg, ed) for(int i = (bg); i <= (ed); i++)
#define fdn(i, bg, ed) for(int i = (bg); i >= (ed); i--)
#define mms(f, x) memset(f,x,sizeof f)
typedef long long lld;
using namespace std;
struct AutoIO {
AutoIO() {
freopen("edit.in", "r", stdin);
freopen("edit.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
~AutoIO() {
cout.flush();
#ifdef Local
cerr << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl;
#endif
}
}__cdl_auto_io;
#ifdef Debug
FILE* dbg_stream = fopen("dbg.log", "w");
#define pdbg(...) fprintf(dbg_stream, __VA_ARGS__)
#else
#define pdbg(...) 1
#endif
int T, n;
string s[2], t[2];
int ans = 0;
int c0[2], c1[2];
int lst[2], lim, lp;
void solve(int tc) {
ans=0;
mms(lst, 0);
lim = 0;
mms(c0, 0);
mms(c1, 0);
lp=-1;
cin >> n;
fup(p, 0, 1) cin >> s[p], s[p] = " " + s[p];
fup(p, 0, 1) cin >> t[p], t[p] = " " + t[p];
int pos = 1;
fup(i, 1, n+1) {
if(i<=n) c0[s[0][i]-'0']++;
if(i==n+1 || (t[0][i] == '0' && t[1][i] == '0')){
if(i<=n) c0[s[0][i]-'0']--;
fup(j, pos, i - 1) {
c1[s[1][j]-'0']++;
if(t[1][j] == '0') {
int c_0 = min(c0[0], c1[0]);
int c_1 = min(c0[1], c1[1]);
ans += c_0 + c_1;
c0[0] -= c_0, c0[1] -= c_1;
c1[0] = c1[1] = 0;
}
}
if(lp>=0) {
if(c0[lp]) ans++,c0[lp]--;
}
int c_0 = min(lst[0], c0[0]);
int c_1 = min(lst[1], c0[1]);
if(c_0 + c_1 <= lim) {
ans += c_0 + c_1;
c0[0] -= c_0, c0[1] -= c_1;
}
else {
ans += lim;
if(c_1 < lim) {
c0[0] -= lim-c_1;
}
if(c_0 < lim) {
c0[1] -= lim-c_0;
}
}
lst[0]=lst[1]=0;
lim=0;
lp=-1;
ans += min(c0[0], c1[0]) + min(c0[1], c1[1]);
if(i<=n) ans += s[0][i] == s[1][i];
c0[0] = c0[1] = c1[0] = c1[1] = 0;
pos = i + 1;
}
else if(t[0][i] == '0') {
c0[s[0][i]-'0']--;
fup(j, pos, i - 1) {
c1[s[1][j]-'0']++;
if(t[1][j] == '0') {
int c_0 = min(c0[0], c1[0]);
int c_1 = min(c0[1], c1[1]);
ans += c_0 + c_1;
c0[0] -= c_0, c0[1] -= c_1;
c1[0] = c1[1] = 0;
}
}
if(lp>=0) {
if(c0[lp]) ans++,c0[lp]--;
}
int c_0 = min(lst[0], c0[0]);
int c_1 = min(lst[1], c0[1]);
if(c_0 + c_1 <= lim) {
ans += c_0 + c_1;
c0[0] -= c_0, c0[1] -= c_1;
}
else {
ans += lim;
if(c_1 < lim) {
c0[0] -= lim-c_1;
}
if(c_0 < lim) {
c0[1] -= lim-c_0;
}
}
lim = c1[0] + c1[1];
pdbg("nxt_lim:%d\n",lim);
lst[0] = c0[0], lst[1] = c0[1];
lp = s[0][i]-'0';
c0[s[0][i]-'0']++, c1[s[1][i]-'0']++;
swap(s[0], s[1]), swap(t[0], t[1]);
swap(c0, c1);
c1[0] = c1[1] = 0;
pos = i + 1;
}
pdbg("i: %d, ans: %d\n", i, ans);
}
cout << ans << "\n";
}
signed main() {
cin >> T;
fup(tc, 1, T) solve(tc);
return 0;
}