#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
 ll t;
  cin >> t;
  while (t)
  {
    string s2;
    cin >> s2;
    ll a = 0;
    for (ll i = 0; i < s2.size(); i++)
    {
      if (((i + 1) < s2.size()) && s2[i] == s2[i + 1] && (s2[i] != '#'))
      {
        s2[i + 1] = '#';
        a++;
      }
      if (((i + 2) < (s2.size())) && s2[i] == s2[i + 2] && (s2[i] != '#'))
      {
        s2[i + 2] = '#';
        a++;
      }
    }
    cout << a << endl;
    t--;
  }
 
 return 0;
 
}