#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
char s[2][maxn];
int ss[maxn];
int flag[maxn];
int n;
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    scanf("%d", &n);
    scanf("%s", s[0] + 1);
    scanf("%s", s[1] + 1);
    memset(flag, 0, (n + 10) * sizeof(int));
    int num = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (s[0][i] == '0' && s[1][i] == '0') {
        num++;
        ss[i] = 0;
      }
      if (s[0][i] != s[1][i]) {
        ans += 2;
        ss[i] = 2;
      }
      if (s[0][i] == '1' && s[1][i] == '1') ss[i] = 1;
    }
    int cnt = 0;
    for (int i = 2; i <= n; i++) {
      if (((ss[i] == 1 && ss[i - 1] == 0) || (ss[i] == 0 && ss[i - 1] == 1)) &&
          flag[i - 1] == 0) {
        cnt++;
        flag[i] = flag[i - 1] = 1;
      }
    }
    printf("%d\n", num + cnt + ans);
  }
  return 0;
}
