#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 123, llinf = 1e18 + 829, ura = 684395049517,
                mod = 998244353;
void xru() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void run() {
  cout << "\n";
  system("pause");
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long cnt = 1;
    vector<long long> a;
    for (long long i = 1; i <= n - 1; i++) {
      if (s[i] != s[i - 1]) {
        a.push_back(cnt);
        cnt = 0;
      }
      cnt++;
    }
    a.push_back(cnt);
    long long score = 0, r = 0;
    for (long long i = 0; i <= (long long)(a.size()) - 1; i++) {
      r = max(r, i);
      if (a[i] > 1) {
        score++;
      } else {
        while (r < (long long)(a.size())) {
          if (a[r] > 1) {
            a[r]--;
            score++;
            break;
          }
          r++;
        }
        if (r == (long long)(a.size())) {
          score += ((long long)(a.size()) - i + 1) / 2;
          break;
        }
      }
    }
    cout << score << "\n";
  }
}
