#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
int t, n;
string str;
bool used[N];
int solve() {
  cin >> n >> str;
  int ans = 0;
  int ones = 0;
  for (int i = 0; i < n; i++) {
    int j = i + 1;
    while (str[j] == str[i]) {
      j += 1;
    }
    int sz = j - i;
    if (sz == 1) {
      ones += 1;
    } else {
      ans += 1;
    }
    while (sz > 2 && ones > 0) {
      ones -= 1;
      sz -= 1;
      ans += 1;
    }
    i = j - 1;
  }
  return ans + (ones + 1) / 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    fill(used, used + n, false);
    cout << solve() << '\n';
  }
  return 0;
}
