#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v;
    int ct = 1;
    queue<int> q;
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1])
        ct++;
      else {
        if (ct > 1) q.push(v.size());
        v.push_back(ct);
        ct = 1;
      }
    }
    v.push_back(ct);
    long long ans = 0;
    for (int i = 0; i < v.size(); i++) {
      ans += (v[i] - 1);
      if (ans > i + 1) ans = i + 1;
    }
    cout << ans + ceil((double(v.size()) - ans) / 2) << endl;
  }
}
