#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int store = 0;
    int pos = n - 1;
    while (pos >= 0) {
      int len = 0;
      char tg = s[pos];
      while (pos >= 0 && s[pos] == tg) {
        pos--;
        len++;
      }
      store += len - 1;
      if (store == 0)
        pos--;
      else
        store--;
      ans++;
    }
    cout << ans << "\n";
  }
}
