#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long ct = 1;
    vector<long long> res;
    for (long long i = 1; i < s.size(); i++) {
      if (s[i] == s[i - 1]) {
        ct++;
      } else {
        res.push_back(ct);
        ct = 1;
      }
    }
    res.push_back(ct);
    ct = 0;
    n = res.size();
    long long ans = 0;
    while (ct < res.size() && res[ct] == 1) ct++;
    for (long long i = 0; i < res.size(); i++) {
      if (ct < i) {
        ct = i;
        while (ct < n && res[ct] == 1) ct++;
      }
      if (ct != n) {
        res[ct]--;
        while (ct < n && res[ct] == 1) ct++;
        ans++;
      } else {
        i++;
        ans++;
      }
    }
    cout << ans << '\n';
  }
}
