#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v;
    int i = 0;
    for (; i < n;) {
      int j = i + 1;
      while (s[j] == s[i]) j++;
      v.push_back(j - i);
      i = j;
    }
    i = 0;
    int N = v.size(), j = 0, ans = 0, cnt = 0;
    while (i < N && j < N) {
      if (v[i] > 1) {
        v[i++] = 0;
        ans++;
      } else {
        if (i > j || v[j] <= 1) {
          while (j < N && v[j] <= 1) j++;
        }
        if (j >= N) break;
        v[j]--;
        v[i++] = 0;
        ans++;
      }
    }
    for (auto x : v) {
      if (x == 1) cnt++;
    }
    cout << ans + cnt / 2 + (cnt % 2 != 0) << "\n";
  }
  return 0;
}
