#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int N = 2 * (int)1e5 + 100;
int tc, n, vis[N];
string s;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  cin >> tc;
  while (tc--) {
    cin >> n;
    cin >> s;
    vector<int> len;
    for (int i = 0; i < n; ++i) {
      int j;
      for (j = i; j < n; ++j) {
        if (s[i] != s[j]) break;
      }
      len.emplace_back(j - i);
      i = j - 1;
    }
    int now = 0, ans = 0;
    for (int i = 0; i < int(len.size()); ++i) {
      while (now < int(len.size()) && len[now] == 1) ++now;
      if (now < int(len.size()))
        len[now]--;
      else
        ++i;
      ++ans;
      if (now == i) ++now;
    }
    cout << ans << '\n';
  }
  return 0;
}
