// STUPID.. AS ALWAYS
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define  pll pair<ll,ll>
#define  vll vector<ll>
#define vs vector<string>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
# define ln cout << "\n" ;
#define maxHeap priority_queue<ll>
#define minHeap priority_queue <ll, vector<ll>, greater<ll> > 
#define MOD 1000000009
#define MAX 2000000000000000000
#define MAXN 1000006

void solve(){
    ll n,i,j;
    // cin >> n;
    string s; cin >> s;
    n = s.size();
    ll ans =0;
    for(i=1;i<n;i++){
        if(s[i] == s[i-1] && s[i] != '$'){
            ans ++;
            s[i] = '$';
            // s[i] = s[i-1] +1; if(s[i] == s[i+1]) s[i]++; 
        }
        if(i<n-1 && s[i-1] != '$' && s[i-1] == s[i+1]){
            // s[i+1] = s[i+1] +1; if(s[i] == s[i+1]) s[i+1] ++; 
            // if(i+2<n && s[i+1] == s[i+2]) s[i+1]++;
            // if(s[i+1])
            ans++;
            s[i+1] = '$';
        }
    }
    cout << ans; ln;
}

int main() 
{
	fastio
	ll t; cin >> t; for(ll i=1;i<=t;i++)
	    //cout << "Case #" << i << ": ",
	    solve();
	return 0;
}