#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    vector<int> v;
    int cnt = 0, n, pre = 0, cur = 0;
    string s;
    cin >> n;
    cin >> s;
    while (pre <= n && cur <= n) {
      if (s[pre] == s[cur])
        cur++;
      else {
        v.push_back(cur - pre);
        pre = cur;
        cnt = 0;
      }
    }
    int l = 0, r = 0, ans = 0;
    n = v.size();
    while (l <= r && r < n) {
      if (v[l] > 1)
        l++;
      else {
        while (r < n) {
          if (v[r] == 1)
            r++;
          else
            break;
        }
        if (r < n)
          v[r]--;
        else
          r--, l++;
        l++;
      }
      ans++;
      while (l > r) r++;
    }
    cout << ans << endl;
  }
}
