#include <bits/stdc++.h>
using namespace std;
long long t, n, z, ans, j;
vector<long long> v;
string s;
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    z = 1;
    ans = 0;
    v.clear();
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1])
        z++;
      else {
        v.push_back(z);
        z = 1;
      }
    }
    if (z) v.push_back(z);
    j = 0;
    ans = 0;
    for (int i = 0; i < v.size(); i++) {
      if (j < i) j = i;
      while (j < v.size() && v[j] == 1) j++;
      if (v[i] > 1) {
        ans++;
      } else if (j < v.size()) {
        v[j]--;
        ans++;
      } else {
        ans++, i++;
      }
    }
    cout << ans << endl;
  }
}
