#include <bits/stdc++.h>
using namespace std;
const long long MAX = 100000 + 5;
const long long mod = 1000000000000000 + 7;
const long long LMT = 1000000;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long f[MAX], in[MAX], iff[MAX];
void fact() {
  f[0] = f[1] = 1;
  for (long long i = 2; i < MAX; i++) f[i] = (f[i - 1] * i) % mod;
  in[0] = 1, in[1] = 1;
  for (long long i = 2; i < MAX; i++)
    in[i] = mod - (mod / i) * in[mod % i] % mod;
  iff[0] = 1;
  for (long long i = 1; i < MAX; i++) iff[i] = (in[i] * iff[i - 1]) % mod;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, ans = 0, i, j, k = 0, l, m;
    string s;
    cin >> n >> s;
    vector<long long> trans, extras;
    for (i = 0; i < n; i++) {
      long long cr = 0;
      char ch = s[i];
      while (i < n) {
        if (s[i] != ch) {
          i--;
          break;
        }
        cr++;
        i++;
      }
      trans.push_back(cr);
    }
    n = trans.size();
    i = k = j = 0;
    while (i < n) {
      if (trans[i] > 1) {
        j++;
        k++;
        trans[i]--;
      } else
        i++;
      if (i < j) i = j;
    }
    k += (n - j + 1) / 2;
    cout << k << endl;
  }
  return 0;
}
