#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    if (s.size() == 1) {
      cout << 1 << endl;
      continue;
    }
    long long i, j, k;
    vector<long long> v;
    for (i = 0; i < n; i++) {
      char x = s[i];
      j = i;
      while (j < s.size() && s[j] == x) j++;
      v.push_back(j - i);
      i = j - 1;
    }
    long long cnt = 0;
    long long ans = 0;
    for (i = 0; i < v.size(); i++) {
      if (v[i] == 1) {
        cnt++;
        continue;
      }
      if (cnt == 0) {
        ans++;
        continue;
      }
      if (v[i] - 1 >= cnt) {
        ans += cnt;
        v[i] -= cnt;
        i--;
        cnt = 0;
        continue;
      }
      j = min(v[i] - 1, cnt);
      ans += j;
      cnt -= j;
      cnt++;
    }
    ans += (cnt / 2);
    if (cnt & 1) ans++;
    cout << ans << endl;
  }
}
