#include <bits/stdc++.h>
using namespace std;
int siz[+200500], t[4 * +200500];
void upd(int v, int l, int r, int ps, int val) {
  if (l == r)
    t[v] = val;
  else {
    int md = (l + r) >> 1;
    if (ps <= md)
      upd(v * 2, l, md, ps, val);
    else
      upd(v * 2 + 1, md + 1, r, ps, val);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
int get(int v, int l, int r, int tl, int tr) {
  if (l > r || tl > r || tl > tr || l > tr) return -1;
  if (t[v] <= 1) return -1;
  if (l == r) return l;
  int md = (l + r) >> 1;
  int cur = get(v * 2, l, md, tl, min(md, tr));
  if (cur == -1) return get(v * 2 + 1, md + 1, r, max(tl, md + 1), tr);
  return cur;
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(0);
  iostream::sync_with_stdio(0);
  int q;
  cin >> q;
  while (q--) {
    int ans = 0, i, n, j;
    string s;
    multiset<pair<int, int> > se;
    vector<int> v;
    cin >> n;
    cin >> s;
    for (i = 0; i <= 4 * n; i++) t[i] = 0;
    i = 0;
    while (i < n) {
      j = i;
      while (j < n && s[j] == s[i]) j++;
      upd(1, 0, n, (int)v.size(), j - i);
      siz[(int)v.size()] = j - i;
      v.push_back(j - i);
      i = j;
    }
    for (i = 0; i < (int)v.size(); i++) {
      int cur = get(1, 0, n, i, n);
      if (cur == -1) {
        ans += ((int)v.size() - i + 1) / 2;
        break;
      }
      siz[cur]--;
      ans++;
      upd(1, 0, n, cur, siz[cur]);
    }
    cout << ans << '\n';
  }
}
