#include <bits/stdc++.h>
using namespace std;
const long long int N = 200005;
long long int n;
long long int t[2 * N];
void build() {
  for (long long int i = n - 1; i > 0; --i)
    t[i] = max(t[i << 1], t[i << 1 | 1]);
}
void modify(long long int p, long long int value) {
  for (t[p += n] = value; p > 1; p >>= 1) t[p >> 1] = max(t[p], t[p ^ 1]);
}
long long int query(long long int l, long long int r) {
  r++;
  if (l > r) return 0;
  long long int res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, t[l++]);
    if (r & 1) res = max(res, t[--r]);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T;
  cin >> T;
  while (T--) {
    cin >> n;
    string s;
    cin >> s;
    vector<long long int> v;
    long long int c = 1;
    for (long long int i = 1; i < n; i++) {
      if (s[i] == s[i - 1])
        c++;
      else {
        v.push_back(c);
        c = 1;
      }
    }
    v.push_back(c);
    n = v.size();
    for (long long int i = 0; i < n; i++) t[n + i] = v[i];
    build();
    long long int ans = 0;
    long long int l = v.size();
    for (long long int i = 0; i < l; i++) {
      if (v[i] > 1) {
        ans++;
      } else {
        ans++;
        long long int lo = i + 1, hi = n - 1, p = -1;
        while (lo <= hi) {
          long long int mid = (lo + hi) / 2;
          if (query(lo, mid) > 1) {
            p = mid;
            hi = mid - 1;
          } else
            lo = mid + 1;
        }
        if (p == -1)
          i++;
        else {
          v[p]--;
          modify(p, v[p]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
