#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long> frq;
    int len = 0, i = 0, j = 0;
    while (i < n) {
      while (s[i] == s[i + 1] && i < n - 1) i++;
      frq.push_back(i - j + 1);
      i++;
      j = i;
    }
    i = 0;
    j = 0;
    int cnt = 0;
    while (j < frq.size()) {
      while (j < frq.size() && frq[j] == 1) j++;
      if (j == frq.size()) break;
      if (i == j) {
        cnt++;
        i++;
        j++;
      } else {
        int dif = j - i;
        int val = frq[j] - 1;
        if (dif <= val) {
          cnt += dif;
          frq[j] -= dif;
          i = j;
        } else {
          cnt += val;
          frq[j] = 1;
          i += val;
        }
      }
    }
    cnt += (j - i + 1) / 2;
    cout << cnt << endl;
  }
}
