#include<bits/stdc++.h>
#define int long long
using namespace std;

void fun(string v)
{
    int ans = 0;
    int n = v.size();

    for(int i=0;i<n;i++)
    {
        if(i+1<n and isalpha(v[i]) and v[i]==v[i+1])
        {
            v[i+1]='.';
            ans++;
        }

        if(i+2<n and isalpha(v[i]) and v[i]==v[i+2])
        {
            v[i+2]='.';
            ans++;
        }
    }

    cout<<ans<<endl;
}

int32_t main()
 {


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    cin>>t;

    while(t--)
    {
        string s;
        cin>>s;

        fun(s);
    }

	return 0;
}