#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const long long N = 6e5 + 100;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string str;
    cin >> str;
    vector<int> vec;
    for (int i = 0; i < n; i++) {
      int s = i;
      int len = 0;
      while (i < n && str[i] == str[s]) {
        i++;
        len++;
      }
      vec.push_back(len);
      i--;
    }
    for (int it : vec) {
    }
    int p = 0;
    int ans = 0;
    int m = vec.size();
    for (int i = 0; i < m; i++) {
      ans++;
      if (p == m) {
        i++;
      } else {
        while (p < m && vec[p] == 1) {
          p++;
        }
        if (p == m) {
          i++;
        } else {
          vec[p]--;
          if (p == i) {
            p++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
