#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
int A[200003];
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int sz = 0, cnt = 0;
  queue<int> q1, q2;
  for (int i = 0; i < n; i++) {
    ++cnt;
    if (i + 1 == n || s[i + 1] != s[i]) {
      q1.push(sz);
      if (cnt > 1) q2.push(sz);
      A[sz] = cnt;
      sz++;
      cnt = 0;
    }
  }
  long long res = 0;
  while (q1.size()) {
    res++;
    if (q2.size()) {
      int u = q2.front();
      A[u]--;
      if (A[u] == 1) q2.pop();
      if (q2.size() && q1.front() == q2.front()) q2.pop();
      q1.pop();
    } else {
      q1.pop();
      if (q1.size()) q1.pop();
    }
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
