#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, a[maxn], pre[maxn], nxt[maxn], tot;
char str[maxn];
set<int> s;
inline void del(int i) { nxt[pre[i]] = nxt[i], pre[nxt[i]] = pre[i]; }
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%s", &n, str + 1);
    tot = 0;
    for (int l = 1, r = 0; l <= n; l = r + 1) {
      r = l;
      while (r < n && str[r + 1] == str[l]) r++;
      a[++tot] = r - l + 1;
    }
    for (int i = 1; i <= tot; i++)
      if (a[i] > 1) s.insert(i);
    int ans = 0;
    for (int i = 1; i <= tot;) {
      ans++;
      if (a[i] > 1) {
        s.erase(*s.begin());
        i++;
        continue;
      }
      if (s.empty()) {
        i += 2;
        continue;
      }
      a[*s.begin()]--;
      if (a[*s.begin()] == 1) s.erase(*s.begin());
      i++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
