#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const long long N = 2e5 + 7;
const long long M = 1e9 + 7;
const long long MAXN = 2e18 + 7;
const long long Mod = 998244353;
long long _, i, j, k, n, m, p, q, s, T, t, l, r, o, u, v, w, x, y, z, ans, nex,
    sum, num, len, st, en, sx, sy, tx, ty, th, ma, mi, mod, op, res, flag, cas,
    bk, ret, mid, cnt, now, tmp, rt;
long long a[N], b[N], c[N], dp[N];
char ch;
vector<long long> g[N], h;
string s1, s2, s3;
signed main() {
  long long T = 1;
  T = read();
  while (T--) {
    cin >> n >> s1;
    cnt = 0;
    for (i = 0; i < n; i++) {
      p = i + 1;
      while (p < n && s1[i] == s1[p]) p++;
      a[++cnt] = s1[i] - '0';
      c[cnt] = p - i;
      i = p - 1;
    }
    b[cnt + 1] = 0;
    for (i = cnt; i >= 1; i--) b[i] = b[i + 1] + c[i] - 1;
    ans = s = 0;
    for (i = 1; i <= cnt; i++) {
      if (b[i] <= s) {
        ans = ans + (cnt - i) / 2 + 1;
        break;
      }
      ans++;
      s++;
      s = max(s - (c[i] - 1), 0ll);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
