import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable string alt = "!@#";

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip.dup;
		auto n = s.length.to !(int);
		int res = 0;
		foreach (i; 1..n)
		{
			if (s[i] == s[i - 1] || (i >= 2 && s[i] == s[i - 2]))
			{
				s[i] = alt[i % 3];
				res += 1;
			}
		}
		writeln (res);
	}
}
