#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000, 1024000000")
#pragma GCC optimize(3)
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
const int MAXN = 2e5 + 5;
const long long MOD = 998244353LL;
char s[MAXN];
struct PQNode {
  int id, num;
  bool operator<(const PQNode &rhs) const { return id > rhs.id; }
};
int main() {
  int T;
  scanf("%d", &T);
  for (int cs = 1; cs <= T; ++cs) {
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    int cnt = 1, num = 0;
    vector<int> v;
    priority_queue<PQNode> pq;
    queue<int> q;
    for (int i = 2; i <= n; ++i) {
      if (s[i] == s[i - 1]) {
        ++cnt;
      } else {
        v.push_back(cnt);
        if (cnt > 1)
          pq.push({num, cnt});
        else
          q.push(num);
        cnt = 1;
        ++num;
      }
    }
    v.push_back(cnt);
    if (cnt > 1)
      pq.push({num, cnt});
    else
      q.push(num);
    cnt = 1;
    ++num;
    int sz = v.size();
    vector<bool> vis;
    vis.resize(sz);
    for (int i = 0; i < sz; ++i) vis[i] = false;
    int ans = 0;
    int p = 0;
    while (p < sz) {
      while (p < sz && vis[p]) ++p;
      if (p >= sz) break;
      bool ok = false;
      while (!pq.empty()) {
        PQNode nw = pq.top();
        pq.pop();
        if (vis[nw.id]) continue;
        if (nw.num > 2) {
          pq.push({nw.id, nw.num - 1});
        } else {
          q.push(nw.id);
        }
        ok = true;
        break;
      }
      if (!ok) {
        while (!q.empty()) {
          int nw = q.front();
          q.pop();
          if (vis[nw]) continue;
          ok = true;
          vis[nw] = true;
          break;
        }
      }
      if (!ok) break;
      ++ans;
      while (p < sz && vis[p]) ++p;
      if (p >= sz) break;
      vis[p] = true;
      ++p;
    }
    printf("%d\n", ans);
  }
  return 0;
}
