#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define debug(...) void(0)
#define endl "\n"
#endif
using LL = long long;
constexpr int N = 1e5 + 10;
int n, cnta[2], cntb[2];
char a[N], b[N], ap[N], bp[N];
int rpa[N], rpb[N];
int mian() {
  cin >> n >> a >> b >> ap >> bp;
  ap[n] = bp[n] = '0';
  for (int i = n - 1; i >= 0; i--) {
    if (ap[i] == '0') rpa[i] = i;
    else if (ap[i + 1] == '0') rpa[i] = i;
    else rpa[i] = rpa[i + 1];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (bp[i] == '0') rpb[i] = i;
    else if (bp[i + 1] == '0') rpb[i] = i;
    else rpb[i] = rpb[i + 1];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!i || rpa[i - 1] != rpa[i]) {
      memset(cnta, 0, sizeof cnta);
      for (int j = i; j <= rpa[i]; j++) cnta[a[j] - '0'] += 1;
    }
    if (!i || rpb[i - 1] != rpb[i]) {
      memset(cntb, 0, sizeof cntb);
      for (int j = i; j <= rpb[i]; j++) cntb[b[j] - '0'] += 1;
    }
    debug("rpa[%d] = %d, rpb[%d] = %d, ", i, rpa[i], i, rpb[i]);
    debug("cnta = {%d, %d}, cntb = {%d, %d}\n", cnta[0], cnta[1], cntb[0], cntb[1]);
    if (cnta[0] && cntb[0]) ans += 1, cnta[0] -= 1, cntb[0] -= 1;
    else if (cnta[1] && cntb[1]) ans += 1, cnta[1] -= 1, cntb[1] -= 1;
    else {
      if (cnta[1] && cntb[0]) cnta[1] -= 1, cntb[0] -= 1;
      else if (cnta[0] && cntb[1]) cnta[0] -= 1, cntb[1] -= 1;
      // else assert(false);
    }
  }
  cout << ans << endl;
  return 0;
}
int main() {
#ifndef LOCAL
#ifndef NF
  freopen("edit.in", "r", stdin);
  freopen("edit.out", "w", stdout);
#endif
  cin.tie(nullptr)->sync_with_stdio(false);
#endif
  int t;
  cin >> t;
  while (t--) mian();
  return 0;
}

