#include <bits/stdc++.h>
using namespace std;
long long gcdExtended(long long a, long long b) {
  if (b == 0) {
    return a;
  } else
    return gcdExtended(b, a % b);
}
float pi = 3.1415926535;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test_case = 1;
  cin >> test_case;
  while (test_case--) {
    long long n, count = 1, ans = 0;
    string s;
    cin >> n >> s;
    set<long long> s1;
    long long m[n], z = 0;
    if (n == 1) {
      cout << "1" << endl;
      continue;
    }
    for (long long i = 1; i < n; i++) {
      if (s[i] == s[i - 1] && i == n - 1) {
        count++;
        m[z++] = count;
        count = 1;
      }
      if (s[i] != s[i - 1] && i == n - 1) {
        m[z++] = count;
        count = 1;
        m[z++] = 1;
      } else if (s[i] != s[i - 1]) {
        m[z++] = count;
        count = 1;
      } else
        count++;
    }
    for (long long i = 0; i < z; i++) {
      if (m[i] > 1) s1.insert(i);
    }
    for (long long i = 0; i < z; i++) {
      if (m[i] > 1) {
        ans++;
        s1.erase(s1.begin());
      } else {
        if (s1.empty()) {
          ans++;
          i++;
        } else {
          auto a1 = s1.begin();
          m[*a1]--;
          s1.erase(a1);
          if (m[*a1] > 1) s1.insert(*a1);
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
