#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 200010;
int n;
char s[N];
void solve() {
  cin >> n;
  cin >> s;
  vector<int> v;
  int cnt = 0;
  int las = s[0];
  for (int i = 0; i <= n; ++i) {
    if (s[i] == las)
      cnt++;
    else {
      v.push_back(cnt);
      las = s[i];
      cnt = 1;
    }
  }
  int l = 0, r = 0, res = 0;
  n = v.size();
  while (l <= r && r < n) {
    if (v[l] > 1)
      l++;
    else {
      while (r < n) {
        if (v[r] == 1)
          r++;
        else
          break;
      }
      if (r < n)
        v[r]--;
      else
        r--, l++;
      l++;
    }
    res++;
    while (r < l) r++;
  }
  printf("%d\n", res);
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
