#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int P = 31;
const int MaxM = 200005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    deque<int> d;
    int num = 0;
    for (long long i = (0); i < (n); i++) {
      int j = i;
      int cnt = 0;
      while (j < n && s[i] == s[j]) {
        cnt++;
        j++;
      }
      d.push_back(cnt);
      i = j - 1;
      num++;
    }
    int ans = 0;
    int i = 0;
    int j = 0;
    while (i < d.size()) {
      if (d[i] > 1) {
        while (i > 0 && d[i] > 1) {
          ans++;
          d[i]--;
          d.pop_front();
          i--;
        }
        if (i == 0 && d[i] > 1) {
          ans++;
          d.pop_front();
        }
      } else
        i++;
    }
    if (d.size() % 2)
      ans += (d.size() + 1) / 2;
    else
      ans += d.size() / 2;
    cout << ans << endl;
  }
}
