#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int a[N];
int cnt;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    cnt = 0;
    int n;
    scanf("%d%s", &n, s + 1);
    s[0] = '!';
    for (int i = 1; i <= n; i++) {
      if (s[i] != s[i - 1]) {
        a[++cnt] = 1;
      } else
        a[cnt]++;
    }
    n = cnt;
    int l = 1, r = 1;
    int ans = 0;
    while (l <= n && r <= n) {
      while (r <= n && a[r] <= 1) r++;
      while (l <= n && a[l] <= 0) l++;
      if (r > n || l > n) break;
      ans++;
      a[r]--;
      a[l] = 0;
    }
    if (r == n + 1 && l <= n) ans += (n - l + 2) / 2;
    printf("%d\n", ans);
  }
  return 0;
}
