//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define fast                      \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
#define file                          \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout)
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(s) s.begin(), s.end()
typedef long long ll;
const double pi = acos(-1);
const ll N = 1e5 + 5;

int main()
{
	fast;
	ll tc;
	cin >> tc;
	while (tc--)
	{		
		string s;
		ll n, i, j, ans = 0;
		cin >> s;
		j=s.size();
		char ch = '0';
		for (i = 0; i < j - 1; i++)
		{
			if (i < j - 2)
			{
				if (s[i] == s[i + 1] && s[i] == s[i + 2])ans =ans+2,i=i+2;
				else if (s[i] == s[i + 1])ans++,i++;
				
				else if (s[i] == s[i + 2])
				{
					ans++;
					s[i + 2] = ch;
					ch++;
					ch%='0';
				}
			}
			else if (s[i] == s[i + 1])ans++,i++;
			
		}
		cout << ans << endl;
	}
}