#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 op1 = 0, op2 = 0, ans = 0, idx = 0;
    while (idx != n) {
      long long len = 1;
      while (idx + 1 < n && s[idx + 1] == s[idx]) {
        len++;
        idx++;
      }
      if (len == 1)
        op1++;
      else if (len > 2)
        op2 += (len - 2);
      if (len >= 2) ans++;
      ans += min(op2, op1);
      op1 -= min(op1, op2);
      op2 = 0;
      idx++;
    }
    ans += ((op1 + 1) / 2);
    cout << ans << endl;
  }
}
