#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
using namespace std;
int yh() {
  int ret = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == EOF) return -1;
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar();
  return f ? -ret : ret;
}
template <typename T>
void yh(T& ret) {
  ret = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == EOF) return ret = -1, void();
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar();
  ret = f ? -ret : ret;
}
char s[200005];
int main() {
  for (register int _ = (yh()); _ >= (1); _--) {
    int n = yh();
    queue<int> q;
    scanf("%s", s + 1);
    int bloc = 0;
    for (register int i = (1); i <= (n); i++) {
      if (s[i] == s[i - 1]) {
        q.push(bloc);
      } else
        bloc++;
    }
    int opts = 0, dlt = 0;
    for (register int i = (1); i <= (n); i++) {
      if (q.empty()) break;
      q.pop();
      opts++;
      dlt++;
      while (!q.empty() && q.front() == i) {
        q.pop();
        dlt++;
      }
      dlt++;
    }
    opts += (n - dlt + 1) / 2;
    cout << opts << '\n';
  }
  return 0;
}
