#include <bits/stdc++.h>
using namespace std;
istream& inp = cin;
template <typename T>
T divup(T a, T b) {
  if ((a % b) == 0) return a / b;
  return 1 + a / b;
}
int32_t main() {
  int ntests;
  assert(inp);
  inp >> ntests;
  for (int test = 0; test < ntests; ++test) {
    int n;
    inp >> n;
    string s;
    inp >> s;
    vector<int> prefs;
    int last = 1;
    char prev = s.at(0);
    for (int i = 1; i < s.size(); ++i) {
      if (s.at(i) != prev) {
        prefs.push_back(last);
        last = 1;
      } else
        ++last;
      prev = s.at(i);
    }
    prefs.push_back(last);
    vector<int> maydel;
    for (int i = 0; i < prefs.size(); ++i)
      if (prefs.at(i) > 1) maydel.push_back(i);
    int ops = 0;
    int posP = 0;
    auto posM = maydel.begin();
    while (posP < prefs.size()) {
      if (prefs.at(posP) > 1) {
        ++ops;
        ++posP;
        while (posM != maydel.end() && *posM < posP) ++posM;
      } else {
        if (posM != maydel.end()) {
          --prefs.at(*posM);
          if (prefs.at(*posM) == 1) ++posM;
          ++posP;
          ++ops;
          while (posM != maydel.end() && (*posM < posP)) ++posM;
        } else {
          ++ops;
          posP += 2;
        }
      }
    }
    cout << ops << endl;
  }
  return 0;
}
