#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using ui = unsigned int;

#define mp make_pair
#define eb emplace_back
#define fi first
#define se second

#ifdef _DEBUG
#define dbg(...) __VA_ARGS__
#else
#define dbg(...) void();
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int radint(int l, int r) {
  return uniform_int_distribution<>(l, r)(rng);
}

const int N = 1e5 + 5;
bool s1[N], s2[N], t1[N], t2[N];
int st1[N], st2[N], cnt1[N][2], cnt2[N][2];

int get01() {
  char c = cin.get();
  while (c != '0' && c != '1') c = cin.get();
  return c ^ 48;
}

void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      cnt1[i][j] = cnt2[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    s1[i] = get01();
  }
  for (int i = 1; i <= n; ++i) {
    s2[i] = get01();
  }
  for (int i = 1; i <= n; ++i) {
    t1[i] = get01();
  }
  for (int i = 1; i <= n; ++i) {
    t2[i] = get01();
  }
  for (int i = 1; i <= n; ++i) {
    if (t1[i - 1] == 0) st1[i] = i;
    else st1[i] = st1[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    if (t2[i - 1] == 0) st2[i] = i;
    else st2[i] = st2[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    if (!t1[i]) continue;
    ++cnt1[st1[i]][s1[i]];
  }
  for (int i = 1; i <= n; ++i) {
    if (!t2[i]) continue;
    ++cnt2[st2[i]][s2[i]];
  }
  int ans = 0;
  static int cur1[2], cur2[2];
  cur1[0] = cur1[1] = cur2[0] = cur2[1] = 0;
  for (int i = 1; i <= n; ++i) {
    cur1[0] += cnt1[i][0], cur1[1] += cnt1[i][1];
    cur2[0] += cnt2[i][0], cur2[1] += cnt2[i][1];
    if (!t1[i] && !t2[i]) {
      ans += (s1[i] == s2[i]);
      continue;
    }
    if (!t1[i]) {
      if (cur2[s1[i]]) {
        ++ans;
        --cur2[s1[i]];
      } else {
        --cur2[!s1[i]];
      }
      continue;
    }
    if (!t2[i]) {
      if (cur1[s2[i]]) {
        ++ans;
        --cur1[s2[i]];
      } else {
        --cur1[!s2[i]];
      }
      continue;
    }
    if (cur1[0] && cur2[0]) {
      ans++;
      --cur1[0];
      --cur2[0];
      continue;
    }
    if (cur1[1] && cur2[1]) {
      ans++;
      --cur1[1];
      --cur2[1];
      continue;
    }
    if (cur1[0] && cur2[1]) {
      --cur1[0];
      --cur2[1];
      continue;
    }
    if (cur1[1] && cur2[0]) {
      --cur1[1];
      --cur2[0];
      continue;
    }
  }
  cout << ans << '\n';
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  freopen("edit.in", "r", stdin);
  freopen("edit.out", "w", stdout);
  int tt;
  cin >> tt;
  while (tt--) solve();
  return 0;
}