#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
mt19937 myrand(time(0));
int main() {
  ios::sync_with_stdio(0);
  cin.tie(), cout.tie();
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string str;
    cin >> str;
    vector<int> v, idx;
    for (int i = 0; i < n; i++) {
      int j = i;
      while (j < n && str[i] == str[j]) j++;
      v.push_back(j - i);
      if ((j - i) > 1) idx.push_back((int)v.size() - 1);
      i = j - 1;
    }
    int ans = 0, id = 0;
    for (int i = 0; i < (int)v.size(); i++) {
      if (i == ((int)v.size() - 1))
        ans++;
      else {
        if (v[i] > 1)
          ans++, id++;
        else {
          ans++;
          if (id < (int)idx.size()) {
            if (--v[idx[id]] == 1) id++;
          } else
            i++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
