#include <bits/stdc++.h>
using namespace std;
int n;
int a[209900];
int c[2][209900];
char str[209900];
bool d[209900];
bool cmp(const int &u, const int &v) { return u > v; }
int getMax(int x, int y) { return x > y ? x : y; }
void solve() {
  int i, j, k, from = 1, ans = 0;
  scanf("%d %s", &n, &str);
  if (n <= 2) {
    printf("1\n");
    return;
  }
  i = 0;
  j = 1;
  memset(d, 0, sizeof(d));
  while (i < n) {
    while (j < n && str[j] != str[j - 1]) j++;
    if (j == n) {
      int cnt = 1;
      while (i < n) {
        cnt += (d[i++] == 0);
      }
      ans += cnt / 2;
      break;
    }
    d[j++] = 1;
    char c = str[i];
    while (i < n && (d[i] || str[i] == c)) i++;
    ans++;
    if (i > j) j = i + 1;
  }
  printf("%d\n", ans);
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    solve();
  }
  return 0;
}
