#include <bits/stdc++.h>
using namespace std;
int main() {
  char c, prev;
  int t, n, index;
  vector<int> arr;
  cin >> t;
  while (t--) {
    cin >> n;
    prev = '#';
    index = 0;
    arr = vector<int>(200100);
    for (int i = 0; i < n; i++) {
      cin >> c;
      if (c != prev && prev != '#') index++;
      arr[index]++;
      prev = c;
    }
    int ans = 0;
    int lastGreatest = 0;
    for (int lo = 0, hi = index; lo <= hi;) {
      if (arr[lo] == 1) {
        bool found = false;
        for (int j = max(lo + 1, lastGreatest); j <= hi; j++) {
          if (arr[j] > 1) {
            arr[j]--;
            found = true;
            lastGreatest = j;
            break;
          }
        }
        if (!found) {
          lastGreatest = hi;
          hi--;
        }
      }
      ans++;
      lo++;
    }
    cout << ans << endl;
  }
}
