#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int oo = 1e9;
const long long OO = 1e18;
template <typename A, typename B>
istream& operator>>(istream& in, pair<A, B>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& v : a) in >> v;
  return in;
}
template <typename T, size_t N>
istream& operator>>(istream& in, array<T, N>& a) {
  for (size_t i = 0; i < N; i++) in >> a[i];
  return in;
}
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator<<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const list<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  for (const auto& v : a) out << v << ' ';
  return out;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << "[" << name << ": " << arg1 << "]" << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr << "[";
  cerr.write(names, comma - names) << ": " << arg1 << "]  ";
  __f(comma + 2, args...);
}
template <typename Arg1>
void print(Arg1&& arg1) {
  cout << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void print(Arg1&& arg1, Args&&... args) {
  cout << arg1 << ' ';
  print(args...);
}
template <typename Arg1>
void read(Arg1&& arg1) {
  cin >> arg1;
}
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) {
  cin >> arg1;
  read(args...);
}
int nextInt() {
  int x;
  read(x);
  return x;
}
long long nextLong() {
  long long x;
  read(x);
  return x;
}
class Timer {
  string _name;
  clock_t _start;

 public:
  Timer(string name = "Runtime") {
    _name = "[" + name + ": ", _start = clock();
  }
  ~Timer() {
    cerr << _name << double(clock() - _start) / CLOCKS_PER_SEC << "]\n";
  }
};
void solve() {
  int n;
  string s;
  read(n, s);
  int ans = 0;
  vector<int> a;
  for (int i = 1, c = 1; i <= n; i++) {
    if (i < n and s[i] == s[i - 1]) {
      c++;
    } else {
      a.push_back(c);
      c = 1;
    }
  }
  n = a.size();
  int l = 0, r = 0;
  while (l < n) {
    if (a[l] > 1) {
      l++;
      ans++;
    } else {
      r = max(r, l);
      while (r < n and a[r] == 1) r++;
      if (r < n) {
        a[r]--;
        l++;
        ans++;
      } else {
        ans++;
        l += 2;
      }
    }
  }
  print(ans);
}
signed main() {
  Timer ti;
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  cin >> T;
  for (int tt = 1; tt <= T; tt++) {
    solve();
  }
  return 0;
}
