#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;


int main()
{
    int t;
    cin>>t;
    while(t--){
         string s;
         cin>>s;
         ll c=0;
         if(s[0]==s[1]){
              c++;
              s[1]='*';
         }
         for(ll i=2;i<s.size();i++){
              if(s[i-1]==s[i]){
                   c++;
                   s[i]='*';
              }else if(s[i-2]==s[i]){
                   c++;
                   s[i]='*';
              }
         }
         
         cout<<c<<endl;
    }
	return 0;
}