#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  std::vector<long long> v;
  long long i = 0;
  while (i < n) {
    long long j = i + 1;
    while (j < n) {
      if (s[j] == s[i])
        j++;
      else
        break;
    }
    v.push_back(j - i);
    i = j;
  }
  long long ans = 0;
  long long big = 0;
  while (big < v.size()) {
    if (v[big] >= 2)
      break;
    else
      big++;
  }
  i = 0;
  long long hi = v.size();
  while (i < hi) {
    if (v[i] > 1) {
      ans++;
      i++;
    } else if (v[i] == 0) {
      i++;
    } else if (v[i] == 1) {
      ans++;
      big = max(big, i + 1);
      while (big < hi) {
        if (v[big] >= 2)
          break;
        else
          big++;
      }
      if (big < hi && v[big] >= 2) {
        i++;
        v[big]--;
      } else {
        i = i + 2;
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
