#include <bits/stdc++.h>
template <class C>
inline void log_c(const C& c) {}
template <class C>
inline int sz(const C& c) {
  return static_cast<int>(c.size());
}
using namespace std;
using pii = pair<int, int>;
const std::string eol = "\n";
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test_sample_count;
  cin >> test_sample_count;
  while (test_sample_count--) {
    int n;
    cin >> n;
    list<char> s;
    for (int k = 0; k < (n); ++k) {
      char ch;
      cin >> ch;
      s.push_back(ch);
    }
    int ans = 0;
    auto it = s.begin();
    while (!s.empty()) {
      ++ans;
      for (; it != s.end() && next(it) != s.end() && *it != *next(it); ++it) {
      }
      if (it != s.end()) {
        it = s.erase(it);
      } else {
        s.pop_front();
      }
      if (!s.empty()) {
        char ch = s.front();
        for (; !s.empty() && s.front() == ch; s.pop_front()) {
          if (it == s.begin()) ++it;
        }
      }
    }
    cout << ans << eol;
  }
  return 0;
}
