#include <bits/stdc++.h>
using namespace std;
int t, n, a[200001], an;
string s;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n), cin >> s, a[1] = 1, an = 1;
    for (int i = 1; i < n; i++)
      if (s[i] != s[i - 1])
        a[++an] = 1;
      else
        ++a[an];
    a[an + 1] = 0;
    int l = 1, r = 1, ans = 0;
    while (l <= an) {
      while (a[r] == 1) ++r;
      if (r > an) {
        ans += (an - l + 2 >> 1);
        break;
      }
      --a[r], ++l, ++ans, r = max(l, r);
    }
    printf("%d\n", ans);
  }
  return 0;
}
