#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    int i = 0;
    int k = 0;
    int last;
    while (i < n - 1) {
      int j = i;
      if (s[j] != s[j + 1]) {
        k++;
        i = j + 1;
      } else {
        while (s[j] == s[j + 1] && j < n - 1) j++;
        if (j - i + 1 > 2)
          k = k + (j - i + 1) / 2 + 1;
        else
          k++;
        last = j - i + 1;
      }
      i = j + 1;
    }
    if (last > 2) k--;
    cout << k + 1 << endl;
  }
  return 0;
}
