#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int T;
char str[N];
int main() {
  for (scanf("%d", &T); T; T--) {
    int n;
    scanf("%d%s", &n, str + 1);
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    int _1 = 0, ans = 0, len = 0;
    for (int i = 1; i <= n; i++) {
      int j = i;
      for (; j < n; j++) {
        if (str[j] != str[j + 1]) break;
      }
      if (j == i)
        _1++;
      else {
        if (_1 >= j - i)
          ans += j - i, _1 -= j - i - 1;
        else
          ans += _1 + 1, _1 = 0;
        i = j;
      }
    }
    cout << ans + (_1 + 1) / 2 << endl;
  }
  return 0;
}
