#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

  int tc;
  cin >> tc;

  while (tc--) {
    string s;
    cin >> s;

    int ans = 0, n = s.size();
    for (int i = 0; i < n; ++i) {
      bool good = 1;
      if (i-2 >= 0 && s[i] == s[i-2]) good = 0;
      if (i-1 >= 0 && s[i] == s[i-1]) good = 0;

      if (!good) {
        ++ans;
        s[i] = '#';
      }
    }
  
    cout << ans << '\n';
  }
}
