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

typedef long long ll;
#define pb push_back
#define  fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    fast;
    ll t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ll i,ans=0;
        for(i=0;i<s.size();i++)
        {
            if(s[i]==s[i+1]){s[i+1]='1';ans++;}
            else if(i>0&&i<s.size()-1&&s[i-1]==s[i+1]){s[i+1]='1';ans++;}
        }
        cout<<ans<<endl;
    }
}
