#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0, cnt = 0;
  int bank = 0;
  int i = n - 1;
  ;
  while (i >= 0) {
    char x = s[i];
    cnt = 0;
    while (i >= 0 && s[i] == x) i--, cnt++;
    bank += cnt - 1;
    ans++;
    if (bank == 0 && i == -1) {
      break;
    }
    if (bank == 0)
      i--;
    else
      bank--;
  }
  cout << ans << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
