// #include </Users/mariapiacaggianelli/Documents/cp/stdc++.h>
#include <bits/stdc++.h>

using namespace std;

#define MAXN 1e6
#define MOD 1e9+7
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<str> vs;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<str,str> ps;

int T;

int main(){
  T = 1;
  cin >> T;
  while(T--){
    str s; cin >> s;
    int ris = 0;
    for(int i = 1; i < s.size(); i++){
      if (s[i] == s[i-1] || (i > 1 && s[i] == s[i-2])){
        char c = 'a';
        while(c == s[i-1] || (i > 1 && c == s[i-2]) || (i < s.size()-1 && c == s[i+1]) || (i < s.size()-2 && c == s[i+2])) c++;
        s[i] = c;
        ris++;
      }
    }
    cout << ris << "\n";
  }
  return 0;
}
