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

#define int long long int
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void SolveTestCase()
{

	string str;
	cin >> str;
	
	int len = str.length();
	
	str += '.';
	vector<bool>mark(len, false);
	
	for(int i=0; i<len-1; ++i) {
		if(mark[i])
			continue;
		if(str[i] == str[i+1])
			mark[i+1] = true;
		if(str[i] == str[i+2])
			mark[i+2] = true;
	}
	
	int cnt = 0;
	for(int i=0; i<len; ++i)
		if(mark[i])
			cnt += 1;
	
	cout << cnt << endl;

}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int T;
	cin >> T;
	
	while(T--) 
		SolveTestCase();
	
	return 0;
}
