#include<bits/stdc++.h>
using namespace std;
const int N=114514;
char s[N];
int n,v[N],kkr;
int main(){int t;
	scanf("%d",&t);while(t--){kkr=0;
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=2;i<=n;i++){v[i]=0;
		if((s[i]==s[i-1]&&!v[i-1]||s[i]==s[i-2]&&!v[i-2]))v[i]=1,kkr++;
	}printf("%d\n",kkr);
}} 