#include <bits/stdc++.h>
using namespace std;
vector<long long int> arr[1005];
bool yes[1005];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long int> v;
    char c;
    long long int last = 0;
    for (long long int i = 0; i < n; i++) {
      if (i == 0) {
        c = s[i];
        last++;
        continue;
      }
      if (s[i] == c) {
        last++;
      } else {
        c = s[i];
        v.push_back(last);
        last = 1;
      }
    }
    v.push_back(last);
    long long int i = 0;
    long long int j = 0;
    long long int moves = 0;
    n = v.size();
    while (1) {
      if (i >= n) {
        break;
      }
      bool good = true;
      while (v[j] <= 1) {
        j++;
        if (j == n) {
          good = false;
          break;
        }
      }
      if (!good) {
        long long int tot = n - i;
        moves += tot / 2 + tot % 2;
        break;
      }
      v[j]--;
      i++;
      moves++;
      j = max(j, i);
    }
    cout << moves << "\n";
  }
}
