#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 7;
int n, a[maxn];
char s[maxn], t[maxn];
int T;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    int ans = 0;
    scanf("%s%s", s + 1, t + 1);
    s[0] = s[n + 1] = '0';
    for (int i = 1; i <= n; i++) {
      if (t[i] == '1') {
        if (s[i] == '0')
          ans++;
        else if (s[i - 1] == '1') {
          ans++;
          s[i - 1] = '2';
        } else if (s[i + 1] == '1') {
          ans++;
          s[i + 1] = '2';
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
