#include <bits/stdc++.h>
template <class T>
void rd(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
using namespace std;
const int N = 2e5 + 10;
int T, n;
char s[N];
int main() {
  rd(T);
  while (T--) {
    rd(n);
    scanf("%s", s + 1);
    int now = 0, cnt = 0, ans = 0, ghb = 0;
    for (int i = n; i >= 1; i--) {
      now++;
      if (s[i] != s[i - 1]) {
        cnt += now - 1;
        if (cnt > 0)
          ans++, cnt--;
        else
          ghb++;
        now = 0;
      }
    }
    ans += (ghb + 1) / 2;
    printf("%d\n", ans);
  }
  return 0;
}
