#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    string s;
    cin >> n >> s;
    vector<long long> vc;
    char cur = 'x';
    for (long long i = 0; i < n; i++) {
      if (cur != s[i]) {
        vc.push_back(1);
        cur = s[i];
      } else
        vc[vc.size() - 1] = vc.back() + 1;
    }
    long long ct = 0;
    long long ans = 0;
    for (long long i = 0; i < vc.size(); i++) {
      ans++;
      ct = max(ct, i);
      while (ct < vc.size() && vc[ct] < 2) ct++;
      if (ct == vc.size())
        i++;
      else
        vc[ct]--;
    }
    cout << ans << endl;
  }
  return 0;
}
