#include <bits/stdc++.h>
using namespace std;
double pi = 3.141592653589793238462;
string numkey = "0123456789";
string uni = "abcdefghijklmnopqrstuvwxyz";
long long int INF = (1LL << 60);
signed main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    queue<long long int> q;
    long long int curr = 0;
    for (long long int i = 1; i < n; i++) {
      if (s[i] != s[i - 1]) {
        curr++;
      }
      if (s[i] == s[i - 1]) q.push(curr);
    }
    long long int deleted = 0, ans = 0;
    for (long long int i = 0; i < n; i++) {
      if (q.empty() == true) break;
      q.pop();
      deleted++, ans++;
      while (q.empty() == false && q.front() == i) {
        q.pop();
        deleted++;
      }
      deleted++;
    }
    long long int remaining = n - deleted;
    ans += (remaining + 1) / 2;
    cout << ans << "\n";
  }
  return 0;
}
