#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string st;
    cin >> st;
    vector<long long> grps;
    long long cnt = 1;
    for (long long i = 1; i < n; i++) {
      if (st[i] != st[i - 1]) {
        grps.push_back(cnt);
        cnt = 1;
      } else {
        cnt++;
      }
    }
    grps.push_back(cnt);
    long long m = grps.size();
    cnt = 0;
    long long j = 1;
    for (long long i = 0; i < m - 1; i++) {
      if (grps[i] == 0) {
        continue;
      }
      if (grps[i] == 1) {
        j = max(i + 1, j);
        if (j == m) {
          grps[i + 1]--;
        } else {
          while (j < m && grps[j] <= 1) {
            j++;
          }
          if (j != m) {
            grps[j]--;
          } else {
            grps[i + 1]--;
          }
        }
        cnt++;
      } else {
        cnt++;
      }
    }
    if (grps[m - 1]) {
      cnt++;
    }
    cout << cnt << endl;
  }
}
