#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = (sizeof(long long) == 4 ? 1e9 : 2e18) + 1e5;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAXN = 2e5 + 3;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long w = 0;
  queue<long long> arr;
  for (long long i = 0; i < n; ++i) {
    if (i < n && s[i] == s[i + 1]) {
      arr.emplace(i + 1);
    }
  }
  long long ans = 0;
  long long l = 0;
  while (l < n) {
    ++ans;
    while (arr.size() && arr.front() < l) arr.pop();
    if (arr.size() && arr.front() >= l) {
      arr.pop();
    } else {
      while (l + 1 < n && s[l] == s[l + 1]) ++l;
      ++l;
    }
    while (l + 1 < n && s[l] == s[l + 1]) ++l;
    ++l;
  }
  cout << ans << '\n';
}
signed main() {
  const string FILE_NAME = "";
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) solve();
}
