#include<bits/stdc++.h>
using namespace std;
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
#define pb push_back

int solve(){
    string a;
    cin>>a;
    
    int n = a.length(),ans=0;
    a+="..";
    for(int i=1;i<n;i++){
        if(a[i-1] == a[i] && a[i]!=1){ a[i] = 1; ans++;}
        if(a[i-1] == a[i+1] && a[i+1]!=1){ a[i+1] = 1; ans++;}
    }
    cout<<ans<<"\n";
    return 0;

}

int main(){
    #ifndef ONLINE_JUDGE   
    freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);    
    #endif 
    Speed_UP

    int t;
    cin>>t;
    while(t--){
        solve();
    }
}