#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y) {
  x = x % 1000000007;
  if (x == 1) return 1;
  if (y == 0) return 1;
  if (y == 1) return x;
  long long temp = power(x, y >> 1);
  if (y & 1) {
    return ((((temp * temp) % 1000000007) * x) % 1000000007);
  } else
    return ((temp * temp) % 1000000007);
}
void factorial(long long n, vector<long long> &fact) {
  fact[0] = 1;
  fact[1] = 1;
  for (long long i = 2; i <= n; i++)
    fact[i] = (fact[i - 1] * (i % 1000000007)) % 1000000007;
  return;
}
long long inv(long long n) { return power(n, 1000000007 - 2); }
long long ncr(long long n, long long r, vector<long long> &fact) {
  if (r > n) return 0;
  return ((((fact[n] * inv(fact[n - r])) % 1000000007) * inv(fact[r])) %
          1000000007);
}
void find_primes(long long n, vector<long long> &primes) {
  bool isprime[n + 1];
  for (long long i = 0; i <= n; i++) isprime[i] = 1;
  isprime[0] = 0;
  isprime[1] = 0;
  for (long long i = 2; i <= n; i++) {
    if (isprime[i]) {
      for (long long j = i * i; j <= n; j += i) {
        isprime[j] = 0;
      }
    }
  }
  for (long long i = 0; i <= n; i++) {
    if (isprime[i]) {
      primes.push_back(i);
    }
  }
  return;
}
void find_fact1(long long n, vector<long long> &primes,
                vector<unordered_map<long long, long long> > &primfact) {
  vector<long long> cur(n + 1);
  for (long long i = 0; i <= n; i++) {
    cur[i] = i;
  }
  for (auto x : primes) {
    for (long long i = x; i <= n; i += x) {
      long long cnt = 0;
      while (cur[i] % x == 0) {
        cur[i] /= x;
        cnt++;
      }
      primfact[i][x] = cnt;
    }
  }
  return;
}
void find_fact2(long long n, vector<long long> &primes, vector<long long> &sp) {
  for (long long i = 0; i <= n; i++) {
    sp[i] = i;
  }
  for (auto x : primes) {
    for (long long i = x * 2; i <= n; i += x) {
      sp[i] = min(sp[i], x);
    }
  }
  return;
}
void bfs(long long u, vector<vector<long long> > &adj,
         vector<long long> &dist) {
  long long n = adj.size() - 1;
  vector<bool> vis(n + 1, 0);
  vis[u] = 1;
  dist[u] = 0;
  queue<long long> q;
  q.push(u);
  long long level = 1;
  while (!q.empty()) {
    long long k = q.size();
    for (long long i = 0; i < k; i++) {
      long long x = q.front();
      q.pop();
      for (auto y : adj[x]) {
        if (!vis[y]) {
          vis[y] = 1;
          dist[y] = level;
          q.push(y);
        }
      }
    }
    level++;
  }
  return;
}
void f(vector<long long> &v1, vector<long long> &v, long long s, long long e) {
  for (long long i = s; i <= e; i++) v1.push_back(v[i]);
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  queue<long long> q;
  for (long long i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      q.push(i);
    }
  }
  vector<bool> v(n, 0);
  long long i = 0;
  long long ans = 0;
  while (i < n) {
    if (q.empty()) {
      break;
    }
    while (v[i] != 0) {
      i++;
    }
    char c = s[i];
    long long prev = i;
    v[i] = 1;
    long long j = i + 1;
    while (j < n && (v[j] == 1 || s[j] == c)) {
      if (s[j] == c) prev = j;
      v[j] = 1;
      j++;
    }
    v[q.front()] = 1;
    q.pop();
    while (!q.empty() && q.front() <= prev) {
      v[q.front()] = 1;
      q.pop();
    }
    ans++;
    i = j;
  }
  long long temp = 0;
  for (long long k = i; k < n; k++) {
    if (v[k] == 0) temp++;
  }
  ans = ans + (temp + 1) / 2;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
}
