#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const int MOD = 1000000000 + 7;
void solve() {
  int n;
  cin >> n;
  cin.ignore(10000, '\n');
  string s;
  cin >> s;
  vector<int> v;
  int cur_count = -1;
  for (int i = 0; i < (n); ++i) {
    if (cur_count == -1) {
      cur_count = 1;
      continue;
    }
    if (s[i] != s[i - 1]) {
      v.push_back(cur_count);
      cur_count = 1;
    } else {
      cur_count++;
    }
  }
  v.push_back(cur_count);
  int count = 0;
  int l = 0, b = 0;
  while (b < (int)(v).size() && v[b] == 1) b++;
  int r = (int)(v).size() - 1;
  while (l <= r) {
    if (v[l] == 1) {
      if (b == (int)(v).size()) {
        l += 2;
      } else {
        l++;
        v[b]--;
        while (b < (int)(v).size() && v[b] == 1) b++;
      }
    } else {
      if (b == l) {
        b++;
        while (b < (int)(v).size() && v[b] == 1) b++;
      }
      l++;
    }
    count++;
  }
  cout << count << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  for (int i = 0; i < (t); ++i) solve();
}
