#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
const int MXN = 200040;
int cnt[MXN];
bool b[MXN];

ll n,d;
int main(){

    int t;
    cin >> t;
    while(t--){
        
        string s;
        cin >> s;
        int n = s.size();
        int ans = 0;
        bool b[n+3];
        for(int i = 0 ; i < n+3 ; i++){
            b[i] = 0;
        }
        for(int i = 1 ; i < n ; i++){
            if(i == 1){
                if(s[i] == s[i-1]){
                    b[i] = 1;
                    ans++;
                }
                continue;
            }
            if(s[i] != s[i-1] && s[i] != s[i-2])continue;
            if(s[i] == s[i-1] && s[i] == s[i-2]){
                if(b[i-1] && b[i-2])continue;
                b[i] = 1;
                ans++;
                continue;
            }
            if(s[i] == s[i-1] && s[i] != s[i-2]){
                if(b[i-1])continue;
                b[i] = 1;
                ans++;
                continue;
            }
            if(s[i] == s[i-2] && s[i] != s[i-1]){
                if(b[i-2])continue;
                b[i] = 1;
                ans++;
                continue;
            }
        }
        
        cout << ans << "\n";
        
    }

}