#include <bits/stdc++.h>
const long long N = 2e5 + 7;
const long long M = 2e4 + 5;
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const long long inf = 0x7fffffff;
const long long INF = 0x3f3f3f3f;
const double pi = 3.1415926;
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long T;
  cin >> T;
  while (T--) {
    long long n, ans = 1, sum = 0, flag = 0, num = 0;
    cin >> n;
    char str[N];
    for (long long i = 0; i < n; i++) {
      cin >> str[i];
      if (i > 0 && str[i] != str[i - 1]) {
        ans++;
      }
    }
    for (long long i = n - 1; i >= 0; i--) {
      if (i != n - 1 && str[i] != str[i + 1]) {
        if (sum == 1) {
          if (flag == 0) {
            num++;
          } else {
            flag--;
          }
        }
        flag += max(sum - 2, 0ll);
        sum = 1;
      } else {
        sum++;
      }
    }
    if (str[0] != str[1]) {
      if (flag == 0) {
        num++;
      }
    }
    cout << ans - num / 2 << endl;
  }
}
