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

const int MXN = 100005;
int T, N, si1, si2, ans;
pair<int, int> sc1[MXN], sc2[MXN];
char val1[MXN], val2[MXN], mov1[MXN], mov2[MXN];

inline void analyze(char *val, char *mov, pair<int, int> *sc, int& si) {
  for (int i(0); i != N;) {
    int j(i), c0(0), c1(0);
    while (j != N && mov[j] != '0')
      ++(val[j++] == '0' ? c0 : c1);
    if (j == i)
      ++(val[j++] == '0' ? c0 : c1);
    sc[si++] = make_pair(c0, c1);
    i = j;
  }
}

int main() {
  freopen("edit.in", "r", stdin);
  freopen("edit.out", "w", stdout);
  scanf("%d", &T);
  while (T--) {
    scanf("%d %s %s %s %s", &N, val1, val2, mov1, mov2);
    si1 = si2 = ans = 0;
    analyze(val1, mov1, sc1, si1);
    analyze(val2, mov2, sc2, si2);
    for (int i(0), j(0); i != si1 || j != si2;) {
      int t0(min(sc1[i].first, sc2[j].first));
      int t1(min(sc1[i].second, sc2[j].second));
      ans += t0 + t1;
      sc1[i].first -= t0, sc2[j].first -= t0;
      sc1[i].second -= t1, sc2[j].second -= t1;
      int mn(min(sc1[i].first + sc1[i].second, sc2[j].first + sc2[j].second));
      (sc1[i].first ? sc1[i].first : sc1[i].second) -= mn;
      (sc2[j].first ? sc2[j].first : sc2[j].second) -= mn;
      if (sc1[i].first + sc1[i].second == 0) ++i;
      if (sc2[j].first + sc2[j].second == 0) ++j;
    }
    printf("%d\n", ans);
  }
  return 0;
}
