#include <bits/stdc++.h>
 
using namespace std;
 
#define ll              long long
#define l1(i, n)        for (ll i = 1; i <= n; i++)
#define l0(i, n)        for (ll i = 0; i < n; i++)
#define lo(i, s, n)     for (ll i = s; i <= n; i++)
#define sca(n)          scanf("%lld", &n)
#define pri(n)          printf("%lld", n)
#define pb              push_back
#define mp              make_pair
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define ms(a, b)        memset(a, b, sizeof(a));
#define cases(tc)       cout<<"Case "<<tc<<": "
#define nl              cout<<"\n";
#define pnl             printf("\n");
#define pi              acos(-1)
#define mod             1000000007
#define inf             999999999999999999
			
 


 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    */

    ll t;
    cin>>t;
    while(t--){
        string x;
        cin>>x;
        ll cnt=0;
        l1(i, x.size()-1){
            if(x[i]==x[i-1]){
                cnt++;
                x[i]='?';
            }
            else if(i>1 && x[i]==x[i-2]){
                cnt++;
                x[i]='?';
            }
        }

        cout<<cnt;
        nl
    }
    return 0;
}
