#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, j, k;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long> v;
    for (i = 0; i < n;) {
      char c = s[i];
      long long cnt = 0;
      while (i < n && s[i] == c) {
        cnt++;
        i++;
      }
      v.push_back(cnt);
    }
    j = 0;
    while (j < v.size() && v[j] == 1) {
      j++;
    }
    long long cnt = 0;
    i = 0;
    if (j == v.size()) {
      cnt = cnt + (j - i + 1) / 2;
      cout << cnt << endl;
      continue;
    }
    while (i < v.size()) {
      if (i == j) {
        cnt++;
        i++;
        j++;
        while (j < v.size() && v[j] == 1) {
          j++;
        }
        if (j == v.size()) {
          cnt = cnt + (j - i + 1) / 2;
          break;
        }
        continue;
      }
      v[j]--;
      i++;
      cnt++;
      if (v[j] == 1) {
        while (j < v.size() && v[j] == 1) {
          j++;
        }
        if (j == v.size()) {
          cnt = cnt + (j - i + 1) / 2;
          break;
        }
      }
    }
    cout << cnt << endl;
  }
}
