#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  deque<int> x;
  int c = 1, p = s[0];
  for (int i = 1; i < n; i++) {
    if (s[i] == p) {
      c++;
    } else {
      x.push_back(c);
      c = 1;
      p = s[i];
    }
  }
  x.push_back(c);
  int f = 0, r = 0;
  while (x.size()) {
    while (f < x.size() && x[f] == 1) {
      f++;
    }
    if (f < x.size()) {
      x[f]--;
    } else {
      x.pop_front();
    }
    if (x.size()) {
      x.pop_front();
    }
    f = max(0, f - 1);
    r++;
  }
  cout << r << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
