#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
string s;
long long block[maxn];
int p = 0;
long long solve() {
  int q = 1;
  long long ans = 0;
  bool flag = false;
  for (int i = 1; i <= p; i++) {
    if (flag) {
      ans++;
      i++;
      continue;
    }
    if (block[i] > 1)
      ans++;
    else {
      while (q < i || (q <= p && block[q] <= 1)) q++;
      if (q > p) {
        flag = true;
        ans++;
        i++;
      } else {
        block[q]--;
        ans++;
      }
    }
  }
  return ans;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    p = 0;
    int n;
    scanf("%d", &n);
    string s;
    cin >> s;
    block[++p] = 1;
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1]) {
        block[p]++;
      } else {
        block[++p] = 1;
      }
    }
    printf("%lld\n", solve());
  }
  return 0;
}
