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