#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;
const char nl = '\n';
char buff[200043];
void solve() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> buff;
    string s = buff;
    queue<int> q;
    int cur = 0;
    for (int i = 0; i < (n); i++) {
      if (i > 0 and s[i] != s[i - 1]) {
        cur++;
      }
      if (i > 0 and s[i] == s[i - 1]) {
        q.push(cur);
      }
    }
    int deleted = 0;
    int score = 0;
    for (int i = 0; i < (n); i++) {
      if (q.empty()) {
        break;
      }
      q.pop();
      deleted++;
      score++;
      while (!q.empty() and q.front() == i) {
        q.pop();
        deleted++;
      }
      deleted++;
    }
    score += (n - deleted + 1) / 2;
    cout << score << nl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
