
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int t;
    cin>>t;
    char c='#';
    char d='*';
    for(int ii=0;ii<t;ii++)
    {
    string s;
    cin>>s;
    int a=0;
    int n=s.size();
    for(int j=0;j<s.size();j++)
    {
        if(s[j]=='#')
        continue;
        if(j+2<n)
        {
        if(s[j]==s[j+1]&&s[j]==s[j+2])
        {
            a+=2;
            j++;
            j++;
            continue;
        }
        
        if(s[j]==s[j+2])
        {
            a++;
            s[j+2]='#';
            continue;
        }
        }
        if(j+1<n)
        {
        if(s[j]==s[j+1])
        {
            a++;
            j++;
        }
        }
    }
    cout<<a<<endl;
    }
    return 0;
}
