After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.

Orpheus, a famous poet, and musician plans to calm Cerberus with his poetry and safely walk past him. He created a very peculiar poem for Cerberus. It consists only of lowercase English letters.

We call a poem's substring a palindrome if and only if it reads the same backwards and forwards. A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by deleting several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.

Unfortunately, Cerberus dislikes palindromes of length greater than $1$. For example in the poem abaa the hound of Hades wouldn't like substrings aba and aa.

Orpheus can only calm Cerberus if the hound likes his poetry. That's why he wants to change his poem so that it does not contain any palindrome substrings of length greater than $1$.

Orpheus can modify the poem by replacing a letter at any position with any lowercase English letter. He can use this operation arbitrarily many times (possibly zero). Since there can be many palindromes in his poem, he may have to make some corrections. But how many, exactly? Given the poem, determine the minimal number of letters that have to be changed so that the poem does not contain any palindromes of length greater than $1$.


-----Input-----

The first line of the input contains a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases, then $t$ test cases follow.

The first and only line of each test case contains a non-empty string of lowercase English letters, Orpheus' poem.

The sum of the length of Orpheus' poems in all test cases will not exceed $10^5$.


-----Output-----

You should output $t$ lines, $i$-th line should contain a single integer, answer to the $i$-th test case.


-----Examples-----

Input
7
babba
abaac
codeforces
zeroorez
abcdcba
bbbbbbb
a
Output
1
1
0
1
1
4
0


-----Note-----

In the first test case, we can replace the third character with c and obtain a palindrome-less poem bacba.

In the second test case, we can replace the third character with d and obtain a palindrome-less poem abdac.

In the third test case, the initial poem already doesn't contain any palindromes, so Orpheus doesn't need to change anything there.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Dynamic programming

Greedy algorithms


Solutions:
for _ in range(int(input())):
	str = input()
	c = 0
	if len(str) != 1:
		for i in range(1, len(str)):
			if str[i] and (i and str[i] == str[i - 1] or (i >= 2 and str[i] == str[i - 2])):
				str = str[0:i] + '0' + str[i + 1:]
				c += 1
	print(c)


from sys import stdin
input = stdin.readline

def canine(s):
	lst = [i for i in s]
	cnt = 0
	for i in range(len(lst) - 1):
		if lst[i] == lst[i + 1]:
			lst[i + 1] = None
			cnt += 1
		if i > 0:
			if lst[i - 1] == lst[i + 1] and lst[i + 1] != None:
				lst[i + 1] = None
				cnt += 1
	return cnt
for i in range(int(input())):
	print(canine(input().strip()))


def not_pl(string):
	count = 0
	c1 = c2 = None
	for c in string:
		if c1 == c or c2 == c:
			count += 1
			c = None
		c2 = c1
		c1 = c
	return count
for _ in range(int(input())):
	print(not_pl(input()))


n = int(input())
for x in range(n):
	word = list(input())
	count = 0
	if len(word) == 1:
		print(0)
		continue
	elif len(word) == 2:
		if word[0] == word[1]:
			print(1)
		else:
			print(0)
		continue
	else:
		for y in range(0, len(word) - 2):
			if word[y] == word[y + 2] and word[y] != '0' and (word[y + 2] != '0'):
				if y - 1 >= 0:
					if word[y - 1] == word[y]:
						word[y] = '0'
						count += 1
						continue
				word[y + 2] = '0'
				count += 1
		for y in range(0, len(word) - 1):
			if word[y] == word[y + 1] and word[y] != '0':
				word[y] = '0'
				count += 1
	print(count)


from collections import defaultdict as df
t = int(input())
for z in range(t):
	s = input()
	visited = df(lambda : -1)
	count = 0
	for i in range(len(s)):
		if visited[s[i]] != -1:
			x = visited[s[i]]
			if i - x <= 2:
				count += 1
			else:
				visited[s[i]] = i
		else:
			visited[s[i]] = i
	print(count)


def CaninePoetry(s):
	n = len(s)
	c = 0
	if n == 1:
		return 0
	elif n == 2:
		if s[0] == s[1]:
			return 1
		else:
			return 0
	for i in range(1, n):
		if i >= 2 and s[i] == s[i - 2]:
			c = c + 1
			s[i] = 'A'
		elif s[i] == s[i - 1]:
			c = c + 1
			s[i] = 'A'
	return c
t = int(input())
for tt in range(t):
	s = list(input())
	ans = CaninePoetry(s)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	str1 = input()
	(cnt, n) = (0, len(str1))
	li = [1] * n
	for i in range(1, len(str1)):
		if str1[i] == str1[i - 1] and li[i - 1]:
			cnt += 1
			li[i] = 0
		elif i - 2 >= 0 and (str1[i] == str1[i - 2] and li[i - 2]):
			cnt += 1
			li[i] = 0
	print(cnt)


def min_nLettersToChange(poem):
	total = holdWhenLetterChanged = 0
	for iLetter in range(len(poem) - 4):
		if holdWhenLetterChanged:
			holdWhenLetterChanged -= 1
			continue
		(letter1, letter2) = (poem[iLetter], poem[iLetter + 1])
		if letter1 == poem[iLetter + 2]:
			if letter1 == letter2:
				total += 2
				holdWhenLetterChanged = 2
			elif letter2 == poem[iLetter + 3]:
				total += 2
				holdWhenLetterChanged = 3
			else:
				total += 1
				holdWhenLetterChanged = 2
		elif letter1 == letter2:
			total += 1
			holdWhenLetterChanged = 1
	return total
nTestCases = int(input())
tuple((print(min_nLettersToChange(testCase)) for testCase in (input() + '123' for x in range(nTestCases))))


def diversity(s, n):
	if n == 0 or n == 1:
		return 0
	if n == 2:
		if s[0] == s[1]:
			return 1
		else:
			return 0
	count = 0
	a = ['n'] * n
	for i in range(n - 2):
		if s[i] == s[i + 1] and a[i] == 'n' and (a[i + 1] == 'n'):
			count += 1
			a[i + 1] = 'c'
		if s[i] == s[i + 2] and a[i] == 'n' and (a[i + 2] == 'n'):
			count += 1
			a[i + 2] = 'c'
	if s[-1] == s[-2] and a[-1] == 'n' and (a[-2] == 'n'):
		count += 1
	return count
t = int(input())
for _ in range(t):
	s = input()
	print(diversity(s, len(s)))


t = input()

def isPal(s):
	return s == s[::-1] and s[0] != '!'
for test in range(int(t)):
	s = list(input())
	count = 0
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		if isPal(s):
			print(1)
		else:
			print(0)
	else:
		if s[1] == s[0]:
			count = count + 1
			s[1] = '!'
		for i in range(len(s) - 2):
			j = i + 2
			if isPal(s[j - 1:j + 1]) or isPal(s[j - 2:j + 1]):
				count = count + 1
				s[j] = '!'
		print(count)


for t in range(0, int(input())):
	s = list(input())
	i = 1
	ans = 0
	if len(s) == 2 and s[0] == s[1]:
		ans = 1
	else:
		while i < len(s) - 1:
			if s[i - 1] == s[i] and s[i + 1] == s[i]:
				(s[i], s[i + 1]) = ('0', '0')
				i += 2
				ans += 2
			elif s[i] == s[i - 1] and s[i] != '0':
				s[i] = '0'
				i += 1
				ans += 1
			elif s[i] == s[i + 1] and s[i] != '0':
				s[i + 1] = '0'
				i += 1
				ans += 1
			elif s[i - 1] == s[i + 1]:
				s[i + 1] = '0'
				i += 1
				ans += 1
			else:
				i += 1
	print(ans)


for _ in range(int(input())):
	poem = list(input())
	if len(poem) == 1:
		print(0)
		continue
	free = {chr(num) for num in range(ord('a'), ord('z') + 1)}
	n_chngs = 0
	free -= set(poem[:2])
	for i in range(1, 2):
		pivot = poem[i]
		if poem[i - 1] == pivot:
			cand = free.pop()
			while any((cand == suff for suff in poem[i + 1:i + 3])):
				cand = free.pop()
			poem[i] = cand
			n_chngs += 1
	for i in range(2, len(poem)):
		pivot = poem[i]
		if poem[i - 2] == pivot or pivot == poem[i - 1]:
			cand = free.pop()
			while any((cand == suff for suff in poem[i + 1:i + 3])):
				cand = free.pop()
			poem[i] = cand
			n_chngs += 1
		free.add(poem[i - 2])
	print(n_chngs)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint

def main():
	s = input()
	n = len(s)
	ch = [0] * n
	cnt = 0
	for i in range(n):
		if i > 0 and s[i] == s[i - 1]:
			if ch[i] == 0 and ch[i - 1] == 0:
				cnt += 1
				ch[i] = 1
		if i > 1 and s[i] == s[i - 2]:
			if ch[i] == 0 and ch[i - 2] == 0:
				cnt += 1
				ch[i] = 1
	print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


import sys, os, io
for _ in range(int(input())):
	s = list(input())
	cnt = 0
	for i in range(len(s) - 1, 0, -1):
		if s[i] == -1:
			continue
		if s[i] == s[i - 1]:
			s[i - 1] = -1
			cnt += 1
		if i > 1 and s[i] == s[i - 2]:
			s[i - 2] = -1
			cnt += 1
	print(cnt)


from sys import stdin
import sys
tt = int(stdin.readline())
for loop in range(tt):
	s = list(stdin.readline()[:-1])
	N = len(s)
	ans = 0
	for i in range(1, N):
		if i == 1:
			if s[i] == s[i - 1]:
				ans += 1
				s[i] = '?'
		elif s[i] == s[i - 1] or s[i] == s[i - 2]:
			s[i] = '?'
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	(n, arr) = (len(s), [v for v in s])
	ans = 0
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			arr[i] = '1'
			ans += 1
		elif i > 1 and arr[i] == arr[i - 2]:
			arr[i] = '1'
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	myString = list(input())
	result = 0
	for iK in range(1, len(myString)):
		if iK >= 2 and myString[iK] == myString[iK - 2] or myString[iK] == myString[iK - 1]:
			result += 1
			myString[iK] = 'A'
	print(result)


import sys
for _ in range(int(input().strip())):
	s = input().strip()
	ans = 0
	for i in range(1, len(s)):
		if s[i - 1] == s[i] or (i >= 2 and s[i - 2] == s[i]):
			ans += 1
			s = s[:i] + '?' + s[i + 1:]
	print(ans)


n = int(input())
while n > 0:
	g = list(input())
	lol = 0
	if len(g) == 1:
		print(0)
	else:
		for i in range(1, len(g)):
			if g[i] == g[i - 1] and g[i - 1] != '#':
				g[i] = '#'
				lol += 1
			elif i >= 2 and g[i] == g[i - 2] and (g[i - 2] != '#'):
				g[i] = '#'
				lol += 1
		print(int(lol))
	n -= 1


import sys, os, getpass
import heapq as hq
import math, random, functools, itertools
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve_(srr):
	srr = list(srr)
	if len(srr) == 1:
		return 0
	if srr[1] == srr[0]:
		srr[1] = '.'
	for (i, x) in enumerate(srr[2:], start=2):
		if srr[i] == srr[i - 2] or srr[i] == srr[i - 1]:
			srr[i] = '.'
	log(srr)
	return srr.count('.')

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]
for case_num in range(int(input())):
	srr = input().strip()
	res = solve(srr)
	print(res)


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	a = list(ip().strip())
	n = len(a)
	if n <= 1:
		print(0)
		continue
	elif n == 2:
		if a[0] == a[1]:
			print(1)
		else:
			print(0)
		continue
	ans = 0
	if a[0] == a[1]:
		a[1] = '$'
		ans = 1
	for i in range(2, n):
		if a[i] == a[i - 1] or a[i] == a[i - 2]:
			a[i] = '$'
			ans += 1
	print(ans)


def edit(poem):
	count = 0
	for i in range(1, len(poem)):
		if poem[i] == poem[i - 1]:
			poem[i] = '$'
		if i > 1:
			if poem[i] == poem[i - 2]:
				poem[i] = '$'
	for i in range(len(poem)):
		if poem[i] == '$':
			count += 1
	print(count)
t = int(input())
for _ in range(t):
	poem = list(input())
	edit(poem)


T = int(input())
for tc in range(T):
	poem = input()
	if len(poem) == 0 or len(poem) == 1:
		print(0)
	elif len(poem) == 2:
		if poem[0] == poem[1]:
			print(1)
		else:
			print(0)
	else:
		poem = list(poem)
		count = 0
		if poem[0] == poem[1]:
			count += 1
			poem[1] = '#'
		i = 2
		while i < len(poem):
			if poem[i] == poem[i - 2]:
				count += 1
				poem[i] = '@'
			elif poem[i] == poem[i - 1]:
				count += 1
				poem[i] = '%'
			i += 1
		print(count)


import math
t = int(input())
for i in range(t):
	s = input()
	s = list(s)
	l = len(s)
	if l == 1:
		print(0)
	elif l == 2:
		if s[0] == s[1]:
			print(1)
		else:
			print(0)
	else:
		j = 0
		c = 0
		while j < l:
			if j == l - 1:
				break
			elif j == l - 2:
				if s[j] == s[j + 1]:
					c += 1
				break
			elif s[j] == s[j + 1] and s[j + 1] == s[j + 2]:
				c += 2
				j += 3
			elif s[j] == s[j + 2]:
				c += 1
				s[j + 2] = str(j)
				j += 1
			elif s[j] == s[j + 1]:
				c += 1
				j += 2
			else:
				j += 1
		print(c)


for s in [*open(0)][1:]:
	for i in range(1, len(s)):
		if s[i] == s[i - 1] or (i > 1 and s[i] == s[i - 2]):
			s = s[:i] + '.' + s[i + 1:]
	print(s.count('.'))


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	s1 = input().strip()
	n = len(s1)
	c = 0
	s = []
	a = 0
	l = []
	for i in range(n):
		s.append(s1[i])
		l.append(0)
	for i in range(n):
		if i + 1 < n:
			if s[i] == s[i + 1]:
				l[i] += 1
				l[i + 1] += 1
		if i + 2 < n:
			if s[i] == s[i + 2]:
				l[i] += 1
				l[i + 2] += 1
	b = [0] * n
	for i in range(n):
		if l[i] != 0:
			if i - 2 >= 0 and s[i] == s[i - 2] and (b[i - 2] == 0):
				b[i] = 1
				if i + 1 < n and s[i] == s[i + 1]:
					l[i + 1] -= 1
				if i + 2 < n and s[i] == s[i + 2]:
					l[i + 2] -= 1
			if b[i] != 1:
				if i - 1 >= 0 and s[i] == s[i - 1] and (b[i - 1] == 0):
					b[i] = 1
					if i + 1 < n and s[i] == s[i + 1]:
						l[i + 1] -= 1
					if i + 2 < n and s[i] == s[i + 2]:
						l[i + 2] -= 1
			if b[i] != 1:
				if i + 1 < n and s[i] == s[i + 1]:
					if l[i] < l[i + 1]:
						continue
					else:
						b[i] = 1
						if i + 1 < n and s[i] == s[i + 1]:
							l[i + 1] -= 1
						if i + 2 < n and s[i] == s[i + 2]:
							l[i + 2] -= 1
			if b[i] != 1:
				if i + 2 < n and s[i] == s[i + 2]:
					if l[i] < l[i + 2]:
						continue
					else:
						b[i] = 1
						if i + 1 < n and s[i] == s[i + 1]:
							l[i + 1] -= 1
						if i + 2 < n and s[i] == s[i + 2]:
							l[i + 2] -= 1
	print(sum(b))


def q_1466():

	def solve(s):
		if len(s) <= 1:
			return 0
		changed = set()
		for i in range(len(s) - 2):
			if i in changed:
				continue
			if s[i] == s[i + 1]:
				changed.add(i + 1)
			if s[i] == s[i + 2]:
				changed.add(i + 2)
		if s[-1] == s[-2] and len(s) - 2 not in changed:
			changed.add(len(s) - 1)
		return len(changed)
	t = int(input())
	for test in range(t):
		print(solve(input()))
q_1466()


t = int(input())
for testcase in range(t):
	s = input()
	arr = [char for char in s]
	if len(s) == 1:
		print(0)
		continue
	if len(s) == 2:
		if s[0] == s[1]:
			print('1')
			continue
		else:
			print(0)
			continue
	for i in range(1, len(s)):
		if arr[i] == arr[i - 1]:
			arr[i] = '*'
		if i >= 2:
			if arr[i] == arr[i - 2]:
				arr[i] = '*'
	ans = 0
	for char in arr:
		if char == '*':
			ans += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	ans = 0
	n = len(s)
	changed = [False] * n
	for i in range(1, n):
		if s[i] == s[i - 1] and changed[i - 1] == False or (i > 1 and s[i] == s[i - 2] and (changed[i - 2] == False)):
			ans += 1
			changed[i] = True
	print(ans)


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt, factorial

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
tests = read_int()
freq = [0] * 10 ** 5
for t in range(tests):
	s = list(input().strip())
	n = len(s)
	if n == 1:
		print(0)
		continue
	for i in range(n):
		freq[i] = 0

	def inc(i, j):
		if j < n and s[i] == s[j]:
			freq[i] += 1
			freq[j] += 1
	for i in range(1, n):
		inc(i - 1, i)
		inc(i - 1, i + 1)

	def subs(i, j):
		if j < n and s[i] == s[j] and (s[i] != '.'):
			k = i if freq[i] > freq[j] else j
			m = 0
			for d in (-2, -1, 1, 2):
				p = k + d
				if not 0 <= p < n:
					continue
				if s[p] != '.' and s[p] == s[k]:
					freq[p] -= 1
					m += 1
			s[k] = '.'
			assert freq[k] == m
			freq[k] = 0
			return 1
		return 0
	count = 0
	for i in range(1, n):
		count += subs(i - 1, i)
		count += subs(i - 1, i + 1)
	print(count)


import sys
input = iter(sys.stdin.read().splitlines()).__next__
t = int(input())
output = []
for _ in range(t):
	poem = input()
	ops = 0
	changed = set()
	for i in range(len(poem) - 2):
		if i in changed:
			continue
		if i + 1 not in changed and poem[i] == poem[i + 1]:
			ops += 1
			changed.add(i + 1)
		if i + 2 not in changed and poem[i] == poem[i + 2]:
			ops += 1
			changed.add(i + 2)
	if len(poem) >= 2 and len(poem) - 2 not in changed and (len(poem) - 1 not in changed) and (poem[-2] == poem[-1]):
		ops += 1
	output.append(ops)
print(*output, sep='\n')


def remove_palindromes(poem):
	changes = 0
	length = len(poem)
	for letterIndex in range(1, length):
		if poem[letterIndex] == poem[letterIndex - 1]:
			poem[letterIndex] = 1
			changes += 1
		elif letterIndex >= 2 and poem[letterIndex] == poem[letterIndex - 2]:
			poem[letterIndex] = 1
			changes += 1
	return changes
n = int(input())
for _ in range(n):
	poem = list(input())
	print(remove_palindromes(poem))


def check_case(string):
	string = list(string)
	for i in range(1, len(string)):
		if i == 1:
			if string[i] == string[i - 1]:
				string[i] = '#'
			continue
		if string[i] == string[i - 1] and string[i] == string[i - 2]:
			string[i] = '#'
			string[i - 1] = '#'
		elif string[i] == string[i - 1] or string[i] == string[i - 2]:
			string[i] = '#'
	return string.count('#')
total_cases = int(input())
output = []
for i in range(total_cases):
	case = input()
	output.append(check_case(case))
for case in output:
	print(case)


import sys

def input():
	return sys.stdin.readline().strip()

def inputlist():
	return list(map(int, input().split()))

def printlist(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def print(var):
	sys.stdout.write(str(var) + '\n')
for _ in range(int(input())):
	s = list(input())
	(n, result) = (len(s), 0)
	if n == 1:
		print(0)
	elif n == 2 and s[1] == s[0]:
		print(1)
	elif n == 2:
		print(0)
	else:
		for i in range(n - 2):
			freq = [0] * 26
			if s[i] == s[i + 2] and s[i] != s[i + 1]:
				result += 1
				freq[ord(s[i]) - 97] += 1
				freq[ord(s[i + 1]) - 97] += 1
				if i + 3 < n:
					freq[ord(s[i + 3]) - 97] += 1
				if i + 4 < n:
					freq[ord(s[i + 4]) - 97] += 1
				for k in range(26):
					if freq[k] == 0:
						s[i + 2] = chr(97 + k)
						break
			elif s[i] == s[i + 1] and s[i + 1] == s[i + 2]:
				result += 2
				freq[ord(s[i]) - 97] += 1
				if i + 3 < n:
					freq[ord(s[i + 3]) - 97] += 1
				if i + 4 < n:
					freq[ord(s[i + 4]) - 97] += 1
				if i - 1 >= 0:
					freq[ord(s[i - 1]) - 97] += 1
				for k in range(26):
					if freq[k] == 0:
						s[i + 1] = chr(97 + k)
						freq[k] += 1
						break
				for k in range(26):
					if freq[k] == 0:
						s[i + 2] = chr(97 + k)
						break
			elif s[i] == s[i + 1] and s[i + 1] != s[i + 2]:
				result += 1
				freq[ord(s[i]) - 97] += 1
				freq[ord(s[i + 2]) - 97] += 1
				if i + 3 < n:
					freq[ord(s[i + 3]) - 97] += 1
				if i - 1 >= 0:
					freq[ord(s[i - 1]) - 97] += 1
				for k in range(26):
					if freq[k] == 0:
						s[i + 1] = chr(97 + k)
						break
			elif s[i] != s[i + 1] and s[i + 1] == s[i + 2]:
				result += 1
				freq[ord(s[i]) - 97] += 1
				freq[ord(s[i + 1]) - 97] += 1
				if i + 3 < n:
					freq[ord(s[i + 3]) - 97] += 1
				if i + 4 < n:
					freq[ord(s[i + 4]) - 97] += 1
				for k in range(26):
					if freq[k] == 0:
						s[i + 2] = chr(97 + k)
						break
		print(result)


def solve(s):
	ans = 0
	changed = [True for i in range(len(s))]
	for i in range(1, len(s)):
		if s[i - 1] == s[i] and changed[i - 1]:
			changed[i] = False
			ans += 1
		elif i > 1 and s[i - 2] == s[i] and changed[i - 2]:
			changed[i] = False
			ans += 1
	return ans
t = int(input())
for _ in range(t):
	s = input()
	print(solve(s))


def solve(s):
	ans = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1] or (i >= 2 and s[i] == s[i - 2]):
			s[i] = '0'
			ans += 1
	return ans
for t in range(int(input())):
	s = list(input())
	print(solve(s))


from collections import defaultdict, deque
import sys
import bisect
import math
input = sys.stdin.readline
mod = 1000000007
t = int(input())
for i in range(t):
	l = [i for i in input() if i != '\n']
	if len(l) == 1:
		print(0)
	else:
		(ans, i) = (0, 0)
		while i < len(l):
			if i + 1 < len(l) and l[i] == l[i + 1] and (l[i] != '0'):
				l[i + 1] = '0'
				ans += 1
			if i + 2 < len(l) and l[i] == l[i + 2] and (l[i] != '0'):
				l[i + 2] = '0'
				ans += 1
			i += 1
		print(ans)


def solve():
	w = input()
	a = [0] * len(w)
	an = 0
	for i in range(0, len(w) - 2):
		if a[i] == 0 and w[i] == w[i + 1]:
			an += 1
			a[i + 1] += 1
		if a[i] == 0 and w[i] == w[i + 2]:
			an += 1
			a[i + 2] += 1
	if len(w) > 1:
		i = len(w) - 2
		if a[i] == 0 and w[i] == w[i + 1]:
			an += 1
			a[i + 1] += 1
	print(an)
t = int(input())
for s in range(0, t):
	solve()


for _ in range(int(input())):
	s = input()
	changed = [0] * len(s)
	for i in range(1, len(s)):
		if s[i] == s[i - 1] and (not changed[i - 1]) and (not changed[i]):
			changed[i] = 1
		if i < len(s) - 1 and s[i - 1] == s[i + 1] and (not changed[i - 1]) and (not changed[i + 1]):
			changed[i + 1] = 1
	print(sum(changed))


rep = '0'

def cerbero(poema):
	md = 0
	for i in range(0, len(poema) - 1):
		if len(poema) == 1:
			break
		if not poema[i].isdigit():
			if i < len(poema) - 2:
				if i + 2 <= len(poema):
					if poema[i] == poema[i + 2]:
						poema[i + 2] = rep
						md += 1
			if poema[i] == poema[i + 1]:
				poema[i + 1] = rep
				md += 1
	return md
n = int(input())
for i in range(0, n):
	poema = list(input())
	x = cerbero(poema)
	print(x)


import io
import os

def solve():
	s = list(map(lambda c: ord(c) - ord('a'), input()))
	cost = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1] or (i >= 2 and s[i] == s[i - 2]):
			opt = set(range(26))
			for pos in [i - 2, i - 1, i + 1, i + 2]:
				try:
					opt.remove(s[pos])
				except:
					pass
			s[i] = list(opt)[0]
			cost += 1
	print(cost)
t = int(input())
for _ in range(t):
	solve()


def main():
	n = int(input())
	for i in range(n):
		solve()

def solve():
	s = str(input())
	s = list(s)
	count = 0
	for i in range(1, len(s)):
		if s[i - 1] == s[i] or (i - 2 >= 0 and s[i - 2] == s[i]):
			s[i] = count
			count += 1
	print(count)
main()


t = int(input())
for Z in range(t):
	s = input()
	l = list(s)
	n = len(l)
	if n == 1:
		print(0)
	elif n == 2:
		if s[0] == s[1]:
			print(1)
		else:
			print(0)
	else:
		count = 0
		if l[1] == l[0]:
			l[1] = '*'
			count += 1
		for i in range(2, n):
			if l[i - 2] != '*' and l[i - 2] == l[i]:
				l[i] = '*'
				count += 1
			if l[i - 1] != '*' and l[i - 1] == l[i]:
				l[i] = '*'
				count += 1
		print(count)


t = int(input())
for _ in range(t):
	a = list(input())
	count = 0
	if len(a) == 1:
		print(0)
		continue
	for i in range(len(a) - 2):
		if a[i] == -1:
			count += 1
			continue
		if a[i] == a[i + 1]:
			a[i + 1] = -1
		if a[i] == a[i + 2]:
			a[i + 2] = -1
	if a[-2] == -1:
		count += 1
	if a[-1] == -1:
		count += 1
	if (a[-1] != -1 and a[-2] != -1) and a[-1] == a[-2]:
		count += 1
	print(count)


def readInt():
	return int(input())

def readLine():
	return [int(s) for s in input().split(' ')]

def readString():
	return input()

def ask(st):
	p2 = None
	p1 = None
	now = None
	ret = set()
	for i in range(len(st)):
		s = st[i]
		p2 = p1
		p1 = now
		now = s
		c2 = now == p2
		c1 = now == p1
		if c2 and (not i - 2 in ret):
			ret.add(i)
		if c1 and (not i - 1 in ret):
			ret.add(i)
	return len(ret)
t = readInt()
for _ in range(t):
	s = input()
	print(ask(s))
pass


for _ in range(int(input())):
	a = input()
	b = len(a)
	(c, d) = ([], 0)
	if b == 1:
		print(0)
		continue
	for _ in range(b):
		c.append(0)
	if a[0] == a[1]:
		c[1] = 1
		d += 1
	for _ in range(2, b):
		if c[_ - 2] == 0 and a[_] == a[_ - 2]:
			c[_] = 1
			d += 1
		if c[_ - 2] == 0 and a[_ - 1] == a[_ - 2] and (c[_ - 1] == 0):
			c[_ - 1] = 1
			d += 1
	if c[b - 1] == 0 and c[b - 2] == 0 and (a[b - 1] == a[b - 2]):
		d += 1
	print(d)


for _ in range(int(input())):
	pal = list(input())
	cont = 0
	for j in range(1, len(pal)):
		if pal[j] == pal[j - 1] or (j > 1 and pal[j] == pal[j - 2]):
			pal[j] = ''
			cont += 1
	print(cont)


def solve(s):
	n = len(s)
	replaced = [0] * n
	res = 0
	for i in range(1, n):
		cur_replaced = 0
		if s[i] == s[i - 1] and replaced[i - 1] == 0:
			cur_replaced = 1
		if i >= 2 and s[i] == s[i - 2] and (replaced[i - 2] == 0):
			cur_replaced = 1
		replaced[i] = cur_replaced
		res += cur_replaced
	return res
tt = int(input())
while tt > 0:
	tt -= 1
	s = input()
	print(solve(s))


import typing
import sys
import math
import collections
import bisect
import itertools
import heapq
import decimal
import copy
import operator
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.readline())

def ns():
	return map(int, sys.stdin.readline().split())

def na():
	return list(map(int, sys.stdin.readline().split()))

def na1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def main():
	t = ni()
	alpha = [chr(i) for i in range(97, 97 + 26)]
	for ti in range(t):
		s = list(input())
		n = len(s)
		ans = 0
		for i in range(n):
			flg1 = False
			flg2 = False
			if i > 0:
				if s[i] == s[i - 1]:
					flg1 = True
			if i > 1:
				if s[i] == s[i - 2]:
					flg2 = True
			if flg1 or flg2:
				ans += 1
				bad = set()
				for j in range(max(0, i - 2), min(n, i + 3)):
					if i == j:
						continue
					bad.add(s[j])
				for char in alpha:
					if char not in bad:
						s[i] = char
						break
		print(ans)
main()


alph = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(int(input())):
	s = input()
	t = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1] or (i > 1 and s[i] == s[i - 2]):
			t += 1
			a = alph
			for c in [i - 1, i - 2, i + 1, i + 2]:
				try:
					a = a.replace(s[c], '')
				except:
					pass
			s = s[:i] + a[20] + s[i + 1:]
	print(t)


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	s = sys.stdin.readline().strip()
	n = len(s)
	C = [0] * n
	for i in range(0, n):
		if i > 0:
			if s[i] == s[i - 1] and C[i - 1] != 1:
				C[i] = 1
		if i > 1:
			if s[i] == s[i - 2] and C[i - 2] != 1:
				C[i] = 1
	print(sum(C))


for _ in range(int(input())):
	x = input()
	n = len(x)
	x = x + 'a' * 3
	x = list(x)
	y = 0
	for i in range(n):
		if i == 0:
			continue
		if i == 1:
			if x[i] == x[i - 1]:
				y += 1
				for j in range(26):
					if j + 97 != ord(x[i - 1]) and j + 97 != ord(x[i + 1]) and (j + 97 != ord(x[i + 2])):
						x[1] = chr(97 + j)
						break
		elif x[i] == x[i - 1] or x[i] == x[i - 2]:
			y += 1
			for j in range(26):
				if j + 97 != ord(x[i - 2]) and j + 97 != ord(x[i - 1]) and (j + 97 != ord(x[i + 1])) and (j + 97 != ord(x[i + 2])):
					x[i] = chr(97 + j)
					break
	print(y)


def solve(str):
	marked = [False] * len(str)
	res = 0
	for i in range(1, len(str)):
		if str[i] == str[i - 1] and (not marked[i - 1]):
			marked[i] = True
		if i >= 2 and str[i] == str[i - 2] and (not marked[i - 2]):
			marked[i] = True
		if marked[i]:
			res += 1
	print(res)
test = int(input())
for _ in range(test):
	str = input()
	if len(str) <= 1:
		print(0)
	elif len(str) == 2:
		if str[0] == str[1]:
			print(1)
		else:
			print(0)
	else:
		solve(str)


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	ans = 0
	for i in range(n - 1):
		if i > 0:
			if s[i - 1] == s[i + 1]:
				s[i + 1] = '?'
				ans += 1
		if s[i] != '?':
			if s[i] == s[i + 1]:
				s[i + 1] = '?'
				ans += 1
	print(ans)


def solve(poem):
	index = 0
	ans = 0
	while index < len(poem) - 1:
		if poem[index] == poem[index + 1] and poem[index] != '!':
			poem[index + 1] = '!'
			ans += 1
		if index + 2 < len(poem):
			if poem[index] == poem[index + 2] and poem[index] != '!':
				poem[index + 2] = '!'
				ans += 1
		index += 1
	return ans
for x in range(int(input())):
	print(solve(list(input())))


def cs(s):
	c = 0
	used = [0] * len(s)
	for i in range(1, len(s)):
		if i > 1 and s[i] == s[i - 2] and (used[i - 2] == 0):
			used[i] = 1
			c += 1
		if s[i] == s[i - 1] and used[i - 1] == 0:
			used[i] = 1
			c += 1
	return c
t = int(input())
while t > 0:
	s = input()
	if len(s) > 2:
		print(cs(s))
	elif len(s) == 2 and s[0] != s[1]:
		print(0)
	elif len(s) == 2:
		print(1)
	else:
		print(0)
	t -= 1


from itertools import count
for _ in range(int(input())):
	S = input()
	n = len(S)
	A = [True] * n
	for i in range(1, n):
		if A[i - 1] and S[i - 1] == S[i]:
			A[i] = False
		elif i > 1 and A[i - 2] and (S[i - 2] == S[i]):
			A[i] = False
	print(A.count(False))


import math
import sys
input = sys.stdin.readline

def solve():
	s1 = input().strip()
	mem = [0] * len(s1)
	res = 0
	for i in range(1, len(s1)):
		if not mem[i - 1] and s1[i] == s1[i - 1]:
			res += 1
			mem[i] = 1
		if i > 1 and (not mem[i - 2]) and (s1[i] == s1[i - 2]):
			res += 1
			mem[i] = 1
	print(res)
tt = int(input())
for test in range(tt):
	solve()


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	s = S()
	q = [False for j in range(len(s))]
	ans = 0
	if len(s) == 1:
		print(0)
		continue
	if len(s) > 1 and s[1] == s[0]:
		ans += 1
		q[1] = True
	for i in range(2, len(s)):
		flag = 0
		if s[i] == s[i - 1] and (not q[i - 1]):
			flag = 1
		if s[i] == s[i - 2] and (not q[i - 2]):
			flag = 1
		if flag:
			q[i] = True
			ans += 1
	print(ans)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for __ in range(t):
	s = list(stdin.readline().strip())
	req = [False] * len(s)
	count = 0
	if len(s) >= 2 and s[0] == s[1] and (not (req[0] or req[1])):
		count += 1
		req[1] = True
	for i in range(2, len(s)):
		if s[i] == s[i - 2]:
			if s[i] == s[i - 1]:
				if req[i - 2] and req[i - 1]:
					continue
				elif req[i - 2] or req[i - 1]:
					req[i] = True
					count += 1
				else:
					count += 2
					req[i - 1] = True
					req[i] = True
			elif req[i - 2]:
				continue
			else:
				count += 1
				req[i] = True
		elif s[i] == s[i - 1]:
			if req[i - 1]:
				continue
			else:
				count += 1
				req[i] = True
	if len(s) >= 2 and s[len(s) - 1] == s[len(s) - 2]:
		if not (req[len(s) - 1] or req[len(s) - 2]):
			count += 1
	print(count)


cases = int(input())
ans_list = []
for c in range(cases):
	s = input()
	change = [0 for i in range(len(s))]
	for i in range(1, len(s)):
		change_3 = s[i] == s[i - 2] if i != 1 else False
		change_2 = s[i] == s[i - 1]
		if change_2 and change[i - 1] == 0:
			change[i] = 1
		elif change_3 and change[i - 2] == 0:
			change[i] = 1
	ans_list.append(sum(change))
for val in ans_list:
	print(val)


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	count = 0
	for i in range(n - 1):
		if s[i] == s[i + 1] or (i != 0 and s[i - 1] == s[i + 1]):
			s[i + 1] = '$'
			count += 1
	print(count)


import sys
input = sys.stdin.readline
from collections import Counter
import math
t = int(input())
for _ in range(t):
	arr = list(input().rstrip())
	ans = 0
	for i in range(1, len(arr)):
		if arr[i] == arr[i - 1]:
			ans += 1
			arr[i] = 3 * i
		if i > 1 and arr[i] == arr[i - 2]:
			ans += 1
			arr[i] = 3 * i
	print(ans)


answers = []

def winner(string):
	length = len(string)
	if length == 1:
		answers.append(0)
		return
	if length == 2:
		if string[0] == string[-1]:
			answers.append(1)
			return
		else:
			answers.append(0)
			return
	arr = []
	for s in string:
		arr.append(s)
	for i in range(0, length - 1):
		left = i - 1
		right = i + 1
		if right < length and left >= 0:
			if arr[left] == arr[right]:
				arr[right] = ')'
		left = i
		right = i + 1
		if right < length and left >= 0:
			if arr[left] == arr[right]:
				arr[right] = ')'
	count = 0
	for ele in arr:
		if ele == ')':
			count += 1
	answers.append(count)
t = int(input())
while t:
	string = input()
	winner(string)
	t -= 1
for ans in answers:
	print(ans)


import math
from collections import defaultdict
from sys import stdin
input = stdin.readline
T = int(input())
for _ in range(T):
	s = input()
	s = list(s)
	s.pop()
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		if s[0] != s[1]:
			print(0)
		else:
			print(1)
	else:
		c = 0
		for i in range(1, len(s)):
			if s[i] == s[i - 1]:
				s[i] = '*'
				c += 1
			elif i - 2 >= 0 and s[i - 2] == s[i]:
				s[i] = '*'
				c += 1
		print(c)


import sys, math
input = sys.stdin.readline
t = int(input())

def f(d):
	for i in range(26):
		if chr(97 + i) not in d:
			return chr(97 + i)
for tttt in range(t):
	s = input().strip('\n')
	n = len(s)
	l = []
	for i in s:
		l.append(i)
	for i in range(1, n):
		if l[i] == l[i - 1] or (i - 2 >= 0 and l[i] == l[i - 2]):
			d = {l[i]: 1}
			if i - 2 >= 0:
				d[l[i - 2]] = 1
			if i + 1 < n:
				try:
					d[l[i + 1]] += 1
				except:
					d[l[i + 1]] = 1
			if i + 2 < n:
				try:
					d[l[i + 2]] += 1
				except:
					d[l[i + 2]] = 1
			l[i] = f(d)
	count = 0
	for i in range(n):
		if l[i] != s[i]:
			count += 1
	print(count)


for _ in range(int(input())):
	s = input()
	ans = 0
	used = [0] * len(s)
	for i in range(1, len(s)):
		use_need = 0
		if s[i] == s[i - 1] and used[i - 1] == 0:
			use_need = 1
		if i > 1 and s[i] == s[i - 2] and (used[i - 2] == 0):
			use_need = 1
		used[i] = use_need
		ans += use_need
	print(ans)


def solve():
	s = list('$$' + input())
	ans = 0
	for i in range(2, len(s)):
		if s[i] == s[i - 2] or s[i] == s[i - 1]:
			s[i] = '@'
			ans += 1
	print(ans)
for _ in range(int(input())):
	solve()


def main(s):
	(a, b) = (0, 0)
	rs = 0
	for ch in s:
		if ch in [a, b]:
			rs += 1
			ch = 0
		(a, b) = (b, ch)
	return rs
rs = []
for _ in range(int(input())):
	rs.append(main(input()))
print(*rs, sep='\n')


tc = int(input())
for _ in range(tc):
	st = input()
	s = list(st)
	count = 0
	if len(s) == 1:
		print(0)
	else:
		for i in range(1, len(s)):
			if s[i] == s[i - 1]:
				count += 1
				s[i] = str(i)
			if i != 1 and s[i] == s[i - 2]:
				count += 1
				s[i] = str(i)
		print(count)


from collections import Counter
for _ in range(int(input())):
	s = input()
	d = Counter(s)
	n = len(s)
	ans = 0
	vis = {}
	for i in range(n):
		vis[i] = 0
	i = 0
	while i + 1 < n:
		if vis[i] == 1:
			i += 1
			continue
		elif i + 2 < n and s[i] == s[i + 1] and (s[i] == s[i + 2]):
			ans += 2
			i += 2
		elif s[i] == s[i + 1]:
			ans += 1
			i += 1
		elif i + 2 < n and s[i] == s[i + 2]:
			ans += 1
			vis[i + 2] = 1
		i += 1
	print(ans)


from math import *
import threading
import sys
from collections import *
import itertools
sys.setrecursionlimit(300000)
mod = 10 ** 9
inf = 10 ** 15
yes = 'YES'
no = 'NO'
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def dist(a, b):
	d = abs(a[1] - b[1]) + abs(a[2] - b[2])
	return d

def power_of_n(x, n):
	cnt = 0
	while x % n == 0:
		cnt += 1
		x //= n
	return cnt

def ask(l, r):
	if l == r:
		return -1
	print('?', l, r)
	sys.stdout.flush()
	return int(input())
for _ in range(int(input()) if True else 1):
	s = list(input())
	n = len(s)
	cnt = 0
	if len(s) == 1:
		print(0)
		continue
	elif s[1] == s[0]:
		s[1] = '!'
		cnt += 1
	for i in range(2, n):
		if s[i] == s[i - 1] or s[i] == s[i - 2]:
			s[i] = '!'
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	a = list(input())
	n = len(a)
	cnt = 0
	for i in range(1, n - 1):
		if a[i] == a[i - 1]:
			cnt += 1
			a[i] = str(cnt)
		if a[i - 1] == a[i + 1]:
			cnt += 1
			a[i + 1] = str(cnt)
	if n != 1 and a[-1] == a[-2]:
		cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	l = input()
	i = 1
	c = 0
	n = len(l)
	if n == 1:
		print(0)
		continue
	vis = [0] * n
	while i < n:
		if i > 1:
			if vis[i - 2] == 0 and l[i - 2] == l[i]:
				c += 1
				vis[i] = 1
		if vis[i - 1] == 0:
			if l[i - 1] == l[i]:
				c += 1
				vis[i] = 1
		i += 1
	print(c)


for _ in range(int(input())):
	poem = list(input())
	ans1 = 0
	index = 1
	poem.insert(0, 'KEK')
	poem.append('KEWK')
	while index <= len(poem) - 2:
		if poem[index] == poem[index - 1]:
			ans1 += 1
			poem[index] = str(index)
			index += 1
		elif poem[index] == poem[index + 1]:
			ans1 += 1
			poem[index + 1] = str(index)
			index += 1
		elif poem[index - 1] == poem[index + 1]:
			ans1 += 1
			poem[index + 1] = str(index)
			index += 1
		else:
			index += 1
	print(ans1)


for _ in range(int(input())):
	s = input()
	n = len(s)
	l = [0 for i in range(n)]
	if n == 1 or n == 0:
		print(0)
	else:
		ans = 0
		if s[1] == s[0]:
			ans += 1
			l[1] = 1
		for i in range(2, n):
			if l[i - 1] == 1 and l[i - 2] == 1:
				continue
			if l[i - 1] == 1:
				if s[i] == s[i - 2]:
					l[i] = 1
					ans += 1
			elif l[i - 2] == 1:
				if s[i] == s[i - 1]:
					ans += 1
					l[i] = 1
			elif s[i] == s[i - 1] or s[i] == s[i - 2]:
				ans += 1
				l[i] += 1
		print(ans)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	ar = [0] * n
	ans = 0
	if n > 1:
		if s[0] == s[1]:
			ans += 1
			ar[1] = 1
	for i in range(2, n):
		if s[i] == s[i - 1] and ar[i - 1] == 0:
			ans += 1
			ar[i] = 1
		elif s[i] == s[i - 2] and ar[i - 2] == 0:
			ans += 1
			ar[i] = 1
	print(ans)


q = int(input())
for _ in range(q):
	s = input()
	pairs = [[] for _ in s]
	for i in range(len(s) - 2):
		if s[i] == s[i + 1]:
			pairs[i].append(i + 1)
		if s[i] == s[i + 2]:
			pairs[i].append(i + 2)
	if len(s) > 1 and s[-2] == s[-1]:
		pairs[-2].append(len(s) - 1)
	cnt = 0
	changed = set()
	for i in range(len(s)):
		if i in changed or len(pairs[i]) == 0:
			continue
		for pair in pairs[i]:
			cnt += 1
			changed.add(pair)
	print(cnt)


for s in [*open(0)][1:]:
	t = (0, 0)
	r = 0
	for x in s:
		if x in t:
			x = 0
			r += 1
		t = (t[1], x)
	print(r)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()
	l = list(s)
	ans = 0
	n = len(s)
	for i in range(1, n):
		if i - 1 >= 0 and l[i] == l[i - 1] or (i - 2 >= 0 and l[i] == l[i - 2]):
			l[i] = '*'
			ans += 1
	print(ans)


import sys

def readTasks():
	n = int(sys.stdin.readline())
	tasks = []
	for i in range(n):
		task = sys.stdin.readline().strip()
		tasks.append(task)
	return tasks

def solve(task):
	used = []
	task = list(task)
	changed = 0
	for i in range(1, len(task)):
		use = False
		if task[i] == task[i - 1]:
			use = True
		if i > 1 and task[i] == task[i - 2]:
			use = True
		if use:
			task[i] = str(i)
			changed += 1
	return changed
tasks = readTasks()
for task in tasks:
	print(str(solve(task)))


from math import *
from collections import *
from functools import *
from bisect import *
from itertools import *
from heapq import *
from statistics import *
inf = float('inf')
ninf = -float('inf')
ip = input
alphal = 'abcdefghijklmnopqrstuvwxyz'
alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def ipl():
	return list(map(int, ip().split()))

def ipn():
	return int(ip())

def ipf():
	return float(ip())

def solve():
	s = ip()
	n = len(s)
	r = 0
	i = 1
	u = [False] * n
	while i < n:
		if s[i] == s[i - 1] and (not u[i - 1]):
			u[i] = True
		if i > 1 and s[i] == s[i - 2] and (not u[i - 2]):
			u[i] = True
		r += u[i]
		i += 1
	print(r)
for _ in range(ipn()):
	solve()


for s in [*open(0)][1:]:
	tot = 0
	ls = list(s)
	n = len(s)
	for (i, c) in enumerate(ls):
		if i + 1 < n and ls[i + 1] == c:
			ls[i + 1] = '@'
		if i + 2 < n and ls[i + 2] == c:
			ls[i + 2] = '@'
		if i - 1 > -1 and ls[i - 1] == c:
			ls[i - 1] = '@'
		if i - 2 > -1 and ls[i - 2] == c:
			ls[i - 2] = '@'
	print(ls.count('@'))


for _ in range(int(input())):
	a = list(input())
	diff = 0
	if len(a) == 1:
		print(0)
	elif len(a) == 2:
		if a[0] == a[1]:
			print(1)
		else:
			print(0)
	else:
		for i in range(1, len(a)):
			if a[i] == a[i - 1]:
				a[i] = '0'
				diff += 1
			elif i - 2 >= 0:
				if a[i] == a[i - 2]:
					a[i] = '0'
					diff += 1
		print(diff)


def solve(string):
	count = 0
	for i in range(1, len(string)):
		if string[i] == string[i - 1]:
			string[i] = '#'
			count += 1
		elif i > 1 and string[i] == string[i - 2] and (string[i - 2] != '#'):
			string[i] = '#'
			count += 1
	return count
t = int(input())
for i in range(t):
	string = list(input())
	if len(string) <= 1:
		print(0)
	else:
		print(solve(string))


from sys import stdin, stdout
n = int(stdin.readline())
for _ in range(n):
	s = input()
	n1 = len(s)
	if n1 == 1:
		print(0)
	else:
		(l, c) = ([], 0)
		for x in s:
			l.append(ord(x))
		v = 123
		for x in range(n1 - 2):
			if l[x] == l[x + 1]:
				c += 1
				l[x + 1] = v
				v += 1
			if l[x] == l[x + 2]:
				c += 1
				l[x + 2] = v
				v += 1
		if l[-2] == l[-1]:
			c += 1
		print(c)


from collections import defaultdict as m
from collections import deque
from math import gcd, floor, log
t = int(input())
while t:
	t -= 1
	s = input()
	s += '@@'
	q = len(s)
	w = [0 for i in range(q)]
	u = 0
	for i in range(q - 2):
		if w[i] == 1:
			continue
		(x, y, z) = (s[i], s[i + 1], s[i + 2])
		if x == y and y == z:
			w[i + 1] = 1
			w[i + 2] = 1
			u += 2
		elif x == y:
			w[i + 1] = 1
			u += 1
		elif x == z:
			w[i + 2] = 1
			u += 1
	print(u)


for _ in range(int(input())):
	s = input()
	n = len(s)
	used = [False] * n
	ans = 0
	for i in range(1, len(s)):
		flag = 0
		if s[i] == s[i - 1] and used[i - 1] == False:
			flag = 1
		if i > 1 and s[i] == s[i - 2] and (used[i - 2] == False):
			flag = 1
		if flag == 1:
			used[i] = True
			ans += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	N = list(input())
	c = 0
	for i in range(1, len(N)):
		if N[i] == N[i - 1] or (i > 1 and N[i] == N[i - 2]):
			N[i] = '*'
			c += 1
	print(c)


def solve():
	s = list(input())
	n = len(s)
	ans = 0
	for i in range(1, n):
		if s[i - 1] == s[i] or (i >= 2 and s[i - 2] == s[i]):
			s[i] = '$'
			ans += 1
	print(ans)
import sys, os, io
input = lambda : sys.stdin.readline().rstrip('\r\n')
stdout = io.BytesIO()
sys.stdout.write = lambda s: stdout.write(s.encode('ascii'))
for _ in range(int(input())):
	solve()
os.write(1, stdout.getvalue())


def chec_pal(s):
	if s[0] == s[2]:
		return True
	else:
		return False
for _ in range(int(input())):
	s = input()
	ans = 0
	if len(s) == 1 or len(set(s)) == len(s):
		print(0)
	else:
		n = len(s)
		p = list(s)
		ans = 0
		j = 1
		d = 0
		for i in range(1, n):
			if p[i] == p[i - 1]:
				p[i] = d
				d += 1
				ans += 1
			if i >= 2:
				if chec_pal(p[i - 2:i + 1]):
					p[i] = d
					d += 1
					ans += 1
		print(ans)


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	n = len(s)
	s += 'aaa'
	for i in range(n):
		if i == 0:
			continue
		if i == 1:
			if s[i] == s[i - 1]:
				ans += 1
				for j in range(26):
					if chr(j + ord('a')) != s[i - 1] and chr(j + ord('a')) != s[i + 1] and (chr(j + ord('a')) != s[i + 2]):
						s = s[:i] + chr(j + ord('a')) + s[i + 1:]
						break
		elif s[i] == s[i - 1] or s[i] == s[i - 2]:
			ans += 1
			for j in range(26):
				if chr(j + ord('a')) != s[i - 2] and chr(j + ord('a')) != s[i + 1] and (chr(j + ord('a')) != s[i + 2]):
					s = s[:i] + chr(j + ord('a')) + s[i + 1:]
					break
	print(ans)


import sys
import io, os
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	s = str(input().rstrip())
	s = list(s)
	s = [ord(c) - ord('a') for c in s]
	n = len(s)
	cur = 25
	ans = 0
	for i in range(1, n):
		if i != n - 1:
			if s[i - 1] == s[i] and s[i] == s[i + 1]:
				ans += 2
				cur += 1
				s[i] = cur
				cur += 1
				s[i + 1] = cur
			elif s[i - 1] == s[i + 1]:
				ans += 1
				cur += 1
				s[i + 1] = cur
			elif s[i - 1] == s[i]:
				ans += 1
				cur += 1
				s[i] = cur
		elif s[i - 1] == s[i]:
			ans += 1
			cur += 1
			s[i] = cur
	print(ans)


t = int(input())
for _ in range(t):
	n = input()
	a = [0] * len(n)
	for s in range(len(n)):
		a[s] = n[s]
	ans = 0
	for i in range(len(n) - 1):
		if a[i] != '?':
			if a[i] == a[i + 1]:
				a[i + 1] = '?'
				ans += 1
			if i < len(n) - 2:
				if a[i + 2] == a[i]:
					a[i + 2] = '?'
					ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	x = ['.'] + list(input()) + ['.'] + ['.']
	change = 0
	for i in range(2, len(x) - 2):
		if x[i] == x[i - 1] or x[i] == x[i - 2]:
			for j in range(0, 26):
				k = j + ord('a')
				if k != ord(x[i]):
					if k != ord(x[i - 1]):
						if k != ord(x[i - 2]):
							if k != ord(x[i + 1]):
								if k != ord(x[i + 2]):
									x[i] = chr(k)
									change += 1
									break
	print(change)


for _ in range(int(input())):
	poetry = input().strip() + '!'
	replace = [0 for _ in range(len(poetry))]
	for i in range(1, len(poetry)):
		if poetry[i] == poetry[i - 1] and (not replace[i - 1]):
			replace[i] = 1
		if i > 1 and poetry[i] == poetry[i - 2] and (not replace[i - 2]):
			replace[i] = 1
	print(sum(replace))


import sys
import time
import os
from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	s = list(inp())
	ans = 0
	n = len(s)
	for i in range(1, n):
		if s[i] == s[i - 1]:
			ans += 1
			s[i] = '#'
		elif i - 2 >= 0:
			if s[i] == s[i - 2]:
				ans += 1
				s[i] = '#'
	print(ans)
start_time = time.time()
for _ in range(iinp()):
	solve()


import sys, random, bisect
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush
from math import gcd
mod = int(1000000000.0 + 7)
inf = int(1e+20)
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
ii = lambda : int(input())
py = lambda : print('YES')
pn = lambda : print('NO')
t = ii()
for _ in range(t):
	s = list(input())
	n = len(s)
	res = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			s[i] = '?'
			res += 1
		elif i >= 2 and s[i] == s[i - 2]:
			s[i] = '?'
			res += 1
	print(res)


for t in range(int(input())):
	s = input()
	sch = 0
	if len(s) > 1:
		sup = s[0]
		if s[0] == s[1]:
			sup += '*'
			sch += 1
		else:
			sup += s[1]
		for i in range(1, len(s) - 1):
			if sup[i] == s[i + 1] or sup[i - 1] == s[i + 1]:
				sup += '*'
				sch += 1
			else:
				sup += s[i + 1]
	print(sch)


def canine(s):
	ans = 0
	prev1 = s[0]
	prev2 = ''
	for i in range(1, len(s)):
		if s[i] == prev1 or s[i] == prev2:
			ans += 1
			prev2 = prev1
			prev1 = ''
		else:
			prev2 = prev1
			prev1 = s[i]
	return ans
for i in range(int(input())):
	s = input()
	print(canine(s))


def contar(p):
	marks = [0] * len(p)
	for i in range(1, len(p)):
		mark = 0
		if p[i] == p[i - 1] and marks[i - 1] != 1:
			mark = 1
		if i > 1 and p[i] == p[i - 2] and (marks[i - 2] != 1):
			mark = 1
		marks[i] = mark
	return marks.count(1)
n = int(input())
r = ''
for i in range(0, n):
	p = input()
	r += str(contar(p)) + '\n'
print(r)


for _ in range(int(input())):
	s = input()
	c = [0] * len(s)
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		if s[0] != s[1]:
			print(0)
		else:
			print(1)
	else:
		if s[0] == s[1]:
			c[1] = 1
		for i in range(2, len(s)):
			if s[i] == s[i - 1] and c[i - 1] == 0 or (s[i] == s[i - 2] and c[i - 2] == 0):
				c[i] = 1
		print(sum(c))


import os
import sys
from io import BytesIO, IOBase
import math
import bisect

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n
for xyz in range(0, int(input())):
	s = input()
	change = [0] * len(s)
	n = len(s)
	for i in range(0, n):
		if change[i] != 1:
			if i + 1 < n:
				if s[i] == s[i + 1]:
					change[i + 1] = 1
			if i + 2 < n:
				if s[i] == s[i + 2]:
					change[i + 2] = 1
	print(sum(change))


for _ in range(int(input())):
	a = [char for char in input()]
	ans = 0
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			a[i] = 'W'
			ans += 1
		elif i > 1 and a[i] == a[i - 2]:
			a[i] = 'W'
			ans += 1
	print(ans)


a = int(input())
for i in range(a):
	s = input()
	ans = []
	cnt = 0
	for i in range(len(s)):
		ans.append(s[i])
	for i in range(1, len(ans)):
		if i == 1 and ans[i] == ans[i - 1]:
			cnt += 1
			ans[i] = -1
		elif i != 1 and (ans[i] == ans[i - 1] or ans[i] == ans[i - 2]):
			cnt += 1
			ans[i] = -1
	print(cnt)


T = int(input())
for _ in range(T):
	s1 = input()
	s = [i for i in s1]
	n = len(s)
	i = 0
	ans = 0
	c = 0
	while i < n:
		if i < n - 1 and s[i] == s[i + 1]:
			s[i + 1] = str(c ^ 1)
			ans += 1
			c = c ^ 1
		if i < n - 2 and s[i:i + 3][::-1] == s[i:i + 3]:
			s[i + 2] = str(c ^ 1)
			ans += 1
			c = c ^ 1
		i += 1
	print(ans)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))

def fn(s):
	s = list(s)
	ans = i = 0
	while i < n:
		if i + 2 < n and s[i] == s[i + 1] == s[i + 2] and (s[i] != ' '):
			ans += 2
			i = i + 3
		elif i + 2 < n and s[i] == s[i + 2] and (s[i] != ' '):
			ans += 1
			s[i + 2] = ' '
			i = i + 1
		elif i + 1 < n and s[i] == s[i + 1] and (s[i] != ' '):
			ans += 1
			i = i + 2
		else:
			i += 1
	return ans
for _ in range(nmbr()):
	s1 = input()
	n = len(s1)
	if n == 2:
		if s1[0] == s1[1]:
			print(1)
		else:
			print(0)
		continue
	print(min(fn(s1), fn(s1[::-1])))


from collections import Counter
for ad in range(int(input())):
	s = list(input())
	n = len(s)
	ans = 0
	a = ord('a')
	for i in range(n - 2):
		if s[i] == s[i + 2]:
			ans += 1
			x = [s[i], s[i + 1], s[i + 2]]
			if i < n - 3:
				x.append(s[i + 3])
			if i < n - 4:
				x.append(s[i + 4])
			for j in range(6):
				if chr(a + j) not in x:
					s[i + 2] = chr(a + j)
					break
		if s[i] == s[i + 1]:
			ans += 1
			x = [s[i], s[i + 1]]
			if i > 0:
				x.append(s[i - 1])
			if i < n - 3:
				x.append(s[i + 3])
			if i < n - 2:
				x.append(s[i + 2])
			for j in range(6):
				if chr(a + j) not in x:
					s[i + 1] = chr(a + j)
					break
	if n > 1 and s[-1] == s[-2]:
		ans += 1
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		numLetters = 0
		poem = list(input())
		for i in range(1, len(poem)):
			if poem[i] == poem[i - 1] and i - 1 >= 0 or (poem[i] == poem[i - 2] and i - 2 >= 0):
				poem[i] = '#'
				numLetters += 1
		print(numLetters)
main()


for i in range(int(input())):
	n = list(input())
	summ = 0
	for j in range(1, len(n) - 1):
		if n[j - 1] == n[j + 1] != '-' or n[j] == n[j + 1] != '-':
			n[j + 1] = '-'
			summ += 1
		if n[j - 1] == n[j] != '-':
			n[j] = '-'
			summ += 1
	if len(n) == 2 and n[0] == n[1]:
		print('1')
	else:
		print(summ)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def FIP():
	return map(float, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 6 + 1
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == 1000000000.0:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return

def prime(n, d):
	prm = set()
	while n != 1:
		prm.add(spf[n])
		n = n // spf[n]
	for ele in prm:
		d[ele] = d.get(ele, 0) + 1
	return

def primeFactors(n, d):
	while n % 2 == 0:
		d[2] = d.get(2, 0) + 1
		n = n / 2
	for i in range(3, int(mt.sqrt(n)) + 1, 2):
		while n % i == 0:
			d[i] = d.get(i, 0) + 1
			n = n / i
	if n > 2:
		d[n] = d.get(n, 0) + 1
	return
mod = 998244353

def solve():
	s = stdin.readline()
	n = len(s)
	i = 0
	mov = 0
	opr = [1 for i in range(n)]
	while i < n:
		if opr[i] == 1:
			if i + 2 < n:
				if s[i] == s[i + 2]:
					if s[i] == s[i + 1]:
						mov += 2
						opr[i + 1] = -1
						opr[i + 2] = -1
					else:
						mov += 1
						opr[i + 2] = -1
				elif s[i] == s[i + 1]:
					opr[i + 1] = -1
					mov += 1
			elif i + 1 < n:
				if s[i] == s[i + 1]:
					opr[i + 1] = -1
					mov += 1
		i += 1
	print(mov)
	return
t = II()
for i in range(t):
	solve()


x = []
z = []
count = 0

def conv(string):
	list1 = []
	list1[:0] = string
	return list1
for _ in range(int(input())):
	s = input()
	x.append(s)
for i in x:
	i = conv(i)
	count = 0
	if len(i) == 1:
		count = 0
	elif len(i) == 2:
		if i[0] == i[1]:
			count = 1
		else:
			count = 0
	else:
		for j in range(1, len(i)):
			if i[j] == i[j - 1] or (j - 2 >= 0 and i[j] == i[j - 2]):
				i[j] = '@'
	for b in range(len(i)):
		count += i[b] == '@'
	z.append(count)
for u in z:
	print(u)


t = int(input())
k = 0
for _ in range(t):
	x = list(input())
	ans = 0
	if len(x) == 1:
		print(0)
	elif len(x) == 2:
		if x[0] == x[1]:
			print(1)
		else:
			print(0)
	else:
		n = len(x)
		for i in range(1, n):
			if x[i] == x[i - 1]:
				ans += 1
				x[i] = k
				k += 1
			if i > 1:
				if x[i] == x[i - 2]:
					ans += 1
					x[i] = k
					k += 1
		print(ans)


for s in [*open(0)][1:]:
	op = 0
	s = list(s)
	for i in range(1, len(s)):
		if s[i] == s[i - 1] or (i > 1 and s[i] == s[i - 2]):
			p = s[i - 2:i] + s[i + 1:i + 3]
			for x in range(0, 26):
				if chr(ord('a') + x) not in p:
					s[i] = chr(ord('a') + x)
					break
			op += 1
	print(op)


from sys import stdin

def function(word):
	counter = 0
	if len(word) == 1:
		return 0
	else:
		if word[1] == word[0]:
			word = word[:1] + '+' + word[2:]
			counter += 1
		for i in range(2, len(word)):
			if word[i] == word[i - 1] or word[i] == word[i - 2]:
				word = word[:i] + '+' + word[i + 1:]
				counter += 1
	return counter
n = int(input())
for i in range(n):
	str = stdin.readline()
	print(function(str))


for s in [*open(0)][1:]:
	d = {}
	r = i = 0
	for c in s:
		if i - d.get(c, -3) > 2:
			d[c] = i
		else:
			r += 1
		i += 1
	print(r)


import string
for _ in range(int(input())):
	t = ['#'] + [c for c in input()] + ['#', '#']
	a = set(string.ascii_lowercase)
	c = 0
	for i in range(2, len(t) - 2):
		if t[i] == t[i - 1] or t[i] == t[i - 2]:
			t[i] = (a - set({t[i - 1], t[i - 2], t[i + 1], t[i + 2]})).pop()
			c += 1
	print(c)


import string
for _ in range(int(input())):
	s = input()
	l = len(s)
	cnt = 0
	x = []
	for j in range(l):
		x.append(0)
	for i in range(1, l):
		if i == 1:
			if s[i] == s[i - 1] and x[i - 1] == 0:
				x[i] = 1
				cnt += 1
		elif s[i] == s[i - 1] and x[i - 1] == 0 or (s[i] == s[i - 2] and x[i - 2] == 0):
			x[i] = 1
			cnt += 1
	print(cnt)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	S = list(input().strip())
	S.append('0')
	S.append('1')
	now = 2
	ANS = 0
	for i in range(len(S)):
		if S[i] == S[i - 1]:
			S[i] = str(now)
			now += 1
			ANS += 1
		elif S[i] == S[i - 2]:
			S[i] = str(now)
			now += 1
			ANS += 1
	print(ANS)


from string import ascii_lowercase
n = int(input())
for i in range(n):
	s = list(input())
	n = 0
	count = len(s)
	j = -1
	while j < count:
		j += 1
		if j == count:
			break
		first = j > 0 and s[j] == s[j - 1]
		second = j > 1 and s[j] == s[j - 2]
		if first or second:
			for new_sym in ascii_lowercase:
				if not (j > 0 and new_sym == s[j - 1] or (j > 1 and new_sym == s[j - 1]) or (j < count - 1 and new_sym == s[j + 1]) or (j < count - 2 and new_sym == s[j + 2])):
					n += 1
					s[j] = new_sym
					break
	print(n)


def solution():
	for tc in range(int(input())):
		cnt = 0
		ls = list(input())
		for i in range(len(ls) - 1):
			if i == 0:
				if ls[i] == ls[i + 1]:
					ls[i + 1] = '#'
					cnt += 1
			elif ls[i] != '#' and ls[i] == ls[i + 1]:
				ls[i + 1] = '#'
				cnt += 1
			elif ls[i - 1] != '#' and ls[i - 1] == ls[i + 1]:
				ls[i + 1] = '#'
				cnt += 1
		print(cnt)
solution()


t = int(input())
for _ in range(t):
	s = list(input() + '@@@')
	n = len(s)
	k = 0
	for i in range(n - 3):
		if s[i] == '@':
			continue
		if s[i] == s[i + 1] != '@':
			s[i + 1] = '@'
			k += 1
		if s[i] == s[i + 2]:
			s[i + 2] = '@'
			k += 1
	print(k)


import sys
t = int(input())
for test in range(t):
	poem = sys.stdin.readline().rstrip()
	check = []
	count = 0
	for char in poem:
		if len(check) == 0:
			check.append(char)
		elif len(check) == 1:
			if check[-1] == char:
				count += 1
				check.append('?')
			else:
				check.append(char)
		elif check[-1] == char or check[-2] == char:
			count += 1
			check.append('?')
		else:
			check.append(char)
	print(count)


import sys
from sys import stdin
input = stdin.readline
sys.setrecursionlimit(pow(10, 6))
from collections import defaultdict
dict = defaultdict(int)
for i in range(1, 27):
	theta = i + 96
	dict[chr(theta)] = i

def integer(a):
	return dict[i]

def comparetwo(a):
	b = a[:]
	b.reverse()
	if dict[a[0]] and dict[a[1]] and (a == b):
		return 1
	return 0

def comparethree(a):
	b = a[:]
	b.reverse()
	if dict[a[0]] and dict[a[2]] and (a == b):
		return 1
	return 0
for i in range(int(input())):
	a = list(input())
	count = 0
	for i in range(len(a) - 1):
		if comparetwo(a[i:i + 2]):
			a[i + 1] = str(integer(a[i + 1]))
			count += 1
		if i != len(a) - 2:
			if comparethree(a[i:i + 3]):
				a[i + 2] = str(integer(a[i + 2]))
				count += 1
	print(count)


t = int(input())
for _ in range(t):
	s = list(input())
	c = 0
	for i in range(1, len(s)):
		if i >= 2 and s[i] == s[i - 2] or s[i] == s[i - 1]:
			c += 1
			s[i] = 'A'
	print(c)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		s = list(input().strip())
		n = len(s)
		ans = 0
		for i in range(1, n):
			fl = 0
			for j in range(max(0, i - 2), i):
				if s[j] == s[i]:
					fl = 1
			if not fl:
				continue
			ans += 1
			s[i] = -1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


PRINT = []
for tt in range(int(input())):
	s = input()
	ans = 0
	for i in range(len(s)):
		if i == 0 or s[i] == '#':
			continue
		if s[i] == s[i - 1]:
			ans += 1
			s = s[:i] + '#' + s[i + 1:]
			continue
		if i <= 1:
			continue
		if s[i] == s[i - 2]:
			ans += 1
			s = s[:i] + '#' + s[i + 1:]
	PRINT.append(ans)
print(*PRINT, sep='\n')


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	s = gcl()
	n = len(s)
	dp = [0] * n
	mv = 0
	for i in range(1, n):
		if s[i] == s[i - 1] and dp[i - 1] == 0:
			dp[i] = 1
		if i > 1 and s[i] == s[i - 2] and (dp[i - 2] == 0):
			dp[i] = 1
	mv = 0
	for i in range(n):
		if dp[i]:
			mv += 1
	print(mv)


import sys
t = int(input())
for _ in range(t):
	s = list(input())
	i = 0
	n = len(s)
	res = 0
	while i < n - 1:
		if i + 1 < n and s[i] == s[i + 1] == '_':
			i += 1
			continue
		if i + 2 < n and s[i] == s[i + 1] == s[i + 2]:
			res += 2
			s[i + 1] = s[i + 2] = '_'
		elif i + 2 < n and s[i] == s[i + 2]:
			res += 1
			s[i + 2] = '_'
		elif i + 1 < n and s[i] == s[i + 1]:
			res += 1
			s[i + 1] = '_'
		i += 1
	print(res)


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	ans = 0
	no = 0
	for i in range(1, n):
		if s[i - 1] == s[i]:
			s[i] = str(no)
			no += 1
			ans += 1
		if i + 1 < n and s[i - 1] == s[i + 1]:
			s[i + 1] = str(no)
			no += 1
			ans += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	ar = list(s)
	m = 0
	for i in range(1, len(ar)):
		if ar[i] == ar[i - 1] or (i >= 2 and ar[i] == ar[i - 2]):
			m = m + 1
			ar[i] = '.'
	print(m)


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	if n == 1:
		print(0)
	else:
		ans = 0
		for i in range(1, n):
			if s[i] == s[i - 1] and s[i - 1] != '#':
				s[i] = '#'
				ans += 1
			if i >= 2 and s[i] == s[i - 2] and (s[i - 2] != '#'):
				s[i] = '#'
				ans += 1
		print(ans)


for i in range(int(input())):
	a = list(input())
	alphabet = set(list('abcdefghijklmnopqrstuvwxyz'))
	a_Set = set(a)
	j = 0
	count = 0
	for i in range(1, len(a)):
		nei = set()
		nei.add(a[i - 1])
		nei.add(a[i])
		if i + 1 <= len(a) - 1:
			nei.add(a[i + 1])
		if i + 2 <= len(a) - 1:
			nei.add(a[i + 2])
		if i - 2 >= 0:
			nei.add(a[i - 2])
		w = alphabet.difference(nei)
		q = list(w)
		if a[i] == a[i - 1]:
			a[i] = q[j % len(q)]
			j = +1
			count += 1
		if i - 2 >= 0:
			if a[i] == a[i - 2]:
				a[i] = q[j % len(q)]
				j = j + 1
				count += 1
	print(count)


t = int(input())
for i in range(t):
	s = input()
	count = 0
	s = list(s)
	n = len(s)
	if len(s) == 1:
		print(0)
		continue
	if len(s) == 2:
		if s[0] == s[1]:
			print(1)
		else:
			print(0)
		continue
	for i in range(1, len(s)):
		if s[i] == s[i - 1] or (i - 2 >= 0 and s[i] == s[i - 2]):
			s[i] = '*'
	for i in range(len(s)):
		if s[i] == '*':
			count += 1
	print(count)


t = int(input())
for i in range(t):
	s = input()
	ans = 0
	marked = set()
	for j in range(len(s) - 1):
		if j not in marked:
			if s[j] == s[j + 1]:
				marked.add(j + 1)
				ans += 1
			if j + 2 < len(s) and s[j] == s[j + 2]:
				marked.add(j + 2)
				ans += 1
	print(ans)


for _ in range(int(input())):
	s = str(input())
	a = list(s)
	n = len(s)
	if n == 1:
		print(0)
	elif n == 2:
		if s[0] == s[1]:
			print(1)
		else:
			print(0)
	else:
		l = [[0, 0, 0] for i in range(n)]
		l[0][0] = s[0]
		if s[0] == s[1]:
			l[1][1] = s[1]
		else:
			l[1][0] = s[1]
		for i in range(2, n):
			for j in range(3):
				c = 0
				for k in range(3):
					if l[i - k][j] == s[i]:
						c = 1
				if c == 0:
					l[i][j] = s[i]
		m = n
		for i in range(3):
			z = 0
			for j in range(n):
				if l[j][i] == 0:
					z += 1
			m = min(z, m)
		print(m)


for _ in range(int(input())):
	a = input()
	l = list(a)
	count = 0
	if len(l) == 1:
		print(0)
	else:
		for i in range(1, len(l)):
			if l[i] == l[i - 1] and l[i - 1] != '#':
				l[i] = '#'
				count += 1
			elif i >= 2 and l[i] == l[i - 2] and (l[i - 2] != '#'):
				l[i] = '#'
				count += 1
		print(count)


import math
from itertools import combinations

def count_repeat(word):
	marks = [0] * len(word)
	for i in range(1, len(word)):
		mark = 0
		if word[i] == word[i - 1] and marks[i - 1] != 1:
			mark = 1
		if i > 1 and word[i] == word[i - 2] and (marks[i - 2] != 1):
			mark = 1
		marks[i] = mark
	return marks.count(1)
n = int(input())
r = ''
for i in range(0, n):
	word = input()
	r += str(count_repeat(word)) + '\n'
print(r)


for _ in range(int(input())):
	s = list(input())
	cnt = 0
	t = 1234
	n = len(s) - 1
	for i in range(n):
		if s[i] == s[i + 1]:
			cnt += 1
			s[i + 1] = t
			t += 1
		try:
			if s[i] == s[i + 2]:
				cnt += 1
				s[i + 2] = t
				t += 1
		except:
			pass
	print(cnt)


t = int(input())
for i in range(t):
	s = input()
	mass = []
	for i in range(0, len(s)):
		mass.append(s[i])
	res = 0
	n = 0
	for j in range(len(mass) - 1):
		if mass[j] == mass[j + 1]:
			mass[j + 1] = n
			n += 1
			res += 1
		if j + 2 < len(mass) and mass[j] == mass[j + 2]:
			mass[j + 2] = n
			n += 1
			res += 1
	print(res)


for _ in range(int(input())):
	s = list(input().strip())
	ans = 0
	for i in range(1, len(s)):
		if i > 1:
			if s[i - 2] == s[i]:
				s[i] = i
		if s[i - 1] == s[i]:
			s[i] = i
		if s[i] == i:
			ans += 1
	print(ans)


def isPallindrome(x):
	for i in range(0, int(len(x) / 2)):
		if x[i] != x[len(x) - i - 1]:
			return False
	return True
cases = int(input())
for z in range(cases):
	mylist = [i for i in input()]
	n = len(mylist)
	string = ''
	i = 0
	ans = 0
	while i < n:
		count = 0
		x = mylist[i]
		if x == '@':
			i += 1
			continue
		while i < n and mylist[i] == x and (count < 3):
			count += 1
			i += 1
		if count == 3:
			ans += 2
			string = ''
		elif count == 2:
			ans += 1
			string = ''
		else:
			i -= 1
			if i <= n - 3:
				string = mylist[i] + mylist[i + 1] + mylist[i + 2]
				if isPallindrome(string):
					ans += 1
					mylist[i + 2] = '@'
			i += 1
	print(ans)


from collections import deque, Counter
from collections import defaultdict as dfd
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial, log2
from heapq import heapify, heappush, heappop
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

def nin():
	return int(input())

def ninf():
	return int(file.readline())

def st():
	return input().strip()

def stf():
	return file.readline().strip()

def read():
	return list(map(int, input().strip().split()))

def readf():
	return list(map(int, file.readline().strip().split()))

def readfl():
	return list(map(float, input().strip().split()))

def readffl():
	return list(map(float, file.readline().strip().split()))

def solve():
	for _ in range(nin()):
		s = list(st())
		n = len(s)
		ans = 0
		for i in range(1, n):
			if s[i] == s[i - 1]:
				s[i] = '*'
				ans += 1
			elif i > 1 and s[i] == s[i - 2]:
				s[i] = '*'
				ans += 1
		ans_.append(ans)
solve()
for i in ans_:
	print(i)


for i1 in range(int(input())):
	s = list(input())
	if len(s) == 1:
		print(0)
		continue
	count = 0
	ch = 123
	if s[1] == s[0]:
		s[1] = ch
		count += 1
	for i in range(2, len(s)):
		if s[i] == s[i - 1] or s[i] == s[i - 2]:
			s[i] = ch
			ch = ch - 1
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	changed = [0] * len(s)
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		if s[0] == s[1]:
			print(1)
		else:
			print(0)
	else:
		res = 0
		changedindex = 1
		i = 1
		while i < len(s) - 1:
			mid = s[i] if changed[i] == 0 else changed[i]
			next = s[i + 1] if changed[i + 1] == 0 else changed[i + 1]
			previous = s[i - 1] if changed[i - 1] == 0 else changed[i - 1]
			if previous != mid and mid != next and (previous != next):
				pass
			elif previous == mid and mid != next and (previous != next):
				changed[i] = changedindex
				changedindex += 1
				res += 1
			elif previous != mid and mid == next and (previous != next):
				changed[i + 1] = changedindex
				changedindex += 1
				res += 1
			elif previous != mid and mid != next and (previous == next):
				changed[i + 1] = changedindex
				changedindex += 1
				res += 1
			elif previous == mid and mid == next and (previous == next):
				changed[i + 1] = changedindex
				changedindex += 1
				res += 1
				changed[i] = changedindex
				changedindex += 1
				res += 1
			i += 1
		print(res)


t = int(input())
while t:
	s = list(input())
	c = 0
	if len(s) == 1:
		print(0)
		t = t - 1
		continue
	if s[0] == s[1]:
		c += 1
		s[1] = '#'
	for i in range(2, len(s)):
		if s[i] == s[i - 1]:
			s[i] = '#'
			c += 1
		elif s[i] == s[i - 2]:
			s[i] = '#'
			c += 1
	print(c)
	t = t - 1


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *
from random import randint

def main():
	for _ in range(int(input())):
		s = list(input().rstrip())
		a = 'abcdefghijklmnopqrstuvwxyz'
		n = len(s)
		ans = 0
		for i in range(n - 1):
			if s[i] == s[i + 1]:
				if i + 2 < n:
					if s[i + 2] == s[i]:
						if i + 3 < n:
							for j in a:
								if j != s[i] and j != s[i + 3]:
									s[i + 1] = j
									ans += 1
									break
							if i + 4 < n:
								for j in a:
									if j != s[i + 2] and j != s[i + 3] and (j != s[i + 4]) and (s[i + 1] != j):
										s[i + 2] = j
										ans += 1
										break
							else:
								for j in a:
									if j != s[i + 2] and j != s[i + 1] and (j != s[i + 3]):
										s[i + 2] = j
										ans += 1
										break
						else:
							ans += 1
					else:
						if i + 3 < n:
							for j in a:
								if s[i + 1] != j and j != s[i + 2] and (s[i + 3] != j):
									s[i + 1] = j
									break
						ans += 1
				else:
					ans += 1
			elif i + 2 < n:
				if s[i] == s[i + 2]:
					if i + 4 < n:
						if s[i] == s[i + 4]:
							for j in a:
								if j != s[i] and j != s[i + 1] and (j != s[i + 3]):
									s[i + 2] = j
									ans += 1
									break
						else:
							for j in a:
								if j != s[i + 2] and j != s[i + 4] and (j != s[i + 1]) and (j != s[i + 3]):
									s[i + 2] = j
									ans += 1
									break
					else:
						if i + 3 < n:
							for j in a:
								if j != s[i + 2] and j != s[i + 1] and (j != s[i + 3]):
									s[i + 2] = j
									break
						ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

def answer(s):
	if len(s) == 1:
		return 0
	if len(s) == 2:
		if s[1] == s[0]:
			return 1
		else:
			return 0
	cnt = 0
	m = [False] * len(s)
	if s[1] == s[0]:
		m[1] = True
		cnt += 1
	for i in range(2, len(s)):
		if s[i] == s[i - 1] and m[i - 1] == False:
			m[i] = True
			cnt += 1
		elif s[i] == s[i - 2] and m[i - 2] == False:
			m[i] = True
			cnt += 1
	return cnt

def main():
	t = int(input())
	while t:
		s = sys.stdin.readline().rstrip()
		print(answer(s))
		t -= 1
	return
main()


import sys

def main():
	res = ''
	input = sys.stdin.readline
	print = sys.stdout.write
	t = int(input())
	for _ in range(t):
		a = list(input())
		sub_res = 0
		for i in range(len(a) - 1):
			if a[i] == a[i + 1] != '@':
				a[i + 1] = '#'
				sub_res += 1
			if i != 0 and '@' != a[i - 1] == a[i + 1] != '#':
				a[i + 1] = '@'
				sub_res += 1
		res += str(sub_res) + '\n'
	print(res)
main()


rep = '0'

def caninePoem(poem):
	mod = 0
	for i in range(0, len(poem) - 1):
		if len(poem) == 1:
			break
		if not poem[i].isdigit():
			if i < len(poem) - 2:
				if i + 2 <= len(poem):
					if poem[i] == poem[i + 2]:
						poem[i + 2] = rep
						mod += 1
			if poem[i] == poem[i + 1]:
				poem[i + 1] = rep
				mod += 1
	return mod
num = int(input())
for i in range(0, num):
	poem = list(input())
	x = caninePoem(poem)
	print(x)


t = int(input())
for _ in range(t):
	poem = input()
	n = len(poem)
	dp = [[[n + 1, n + 1] for _ in range(2)] for _ in range(n)]
	for i in range(2):
		for j in range(2):
			dp[0][i][j] = j
	for i in range(1, n):
		if poem[i] == poem[i - 1] == poem[i - 2] and i > 1:
			dp[i][0][1] = dp[i - 1][1][0] + 1
			dp[i][1][1] = min(dp[i - 1][0][1], dp[i - 1][1][1]) + 1
			dp[i][1][0] = dp[i - 1][1][1]
		elif poem[i] == poem[i - 2] and poem[i] != poem[i - 1] and (i > 1):
			dp[i][0][0] = dp[i - 1][1][0]
			dp[i][0][1] = min(dp[i - 1][1][0], dp[i - 1][0][0]) + 1
			dp[i][1][0] = dp[i - 1][1][1]
			dp[i][1][1] = min(dp[i - 1][0][1], dp[i - 1][1][1]) + 1
		elif poem[i] == poem[i - 1]:
			dp[i][0][1] = min(dp[i - 1][0][0], dp[i - 1][1][0]) + 1
			dp[i][1][0] = min(dp[i - 1][1][1], dp[i - 1][0][1])
			dp[i][1][1] = min(dp[i - 1][0][1], dp[i - 1][1][1]) + 1
		else:
			for j in range(2):
				for k in range(2):
					dp[i][j][k] = min(dp[i][j][k], dp[i - 1][0][j], dp[i - 1][1][j]) + k
	ans = n + 1
	for i in range(2):
		for j in range(2):
			ans = min(ans, dp[-1][i][j])
	print(ans)


for _ in range(int(input())):
	s = input()
	s = [s[i] for i in range(len(s))]
	if len(s) == 1:
		print(0)
		continue
	if len(s) == 2:
		if s == s[::-1]:
			print(1)
			continue
	for i in range(1, len(s) - 1):
		if s[i + 1] == s[i - 1] and s[i - 1] == s[i]:
			s[i + 1] = '?'
			s[i] = '?'
		elif s[i - 1] == s[i]:
			if s[i - 1] == '?':
				i += 1
				continue
			s[i] = '?'
		elif s[i + 1] == s[i - 1]:
			s[i + 1] = '?'
		elif s[i] == s[i + 1]:
			s[i + 1] = '?'
	print(s.count('?'))


import math as m
t = int(input())
while t:
	t -= 1
	s = input()
	marked = [0] * len(s)
	for i in range(1, len(s)):
		x = 0
		if s[i] == s[i - 1] and marked[i - 1] == 0:
			x = 1
		if i > 1 and s[i] == s[i - 2] and (marked[i - 2] == 0):
			x = 1
		marked[i] = x
	print(sum(marked))


for test in range(int(input())):
	s = list(input())
	a = len(s)
	p = 0
	for i in range(a - 1):
		if i == 0:
			if s[i] == s[i + 1]:
				s[i + 1] = '0'
				p += 1
				continue
		elif s[i - 1] == s[i + 1]:
			s[i + 1] = '0'
			p += 1
		elif s[i] == s[i + 1]:
			s[i + 1] = '0'
			p += 1
	print(p)


def correct(s):
	t = 0
	for i in range(len(s) - 1):
		if s[i:i + 2] == s[i:i + 2][::-1] and s[i] != '1':
			s = s[:i + 1] + '1' + s[i + 2:]
			t += 1
		if i + 2 < len(s) and s[i:i + 3] == s[i:i + 3][::-1] and (s[i] != '1'):
			s = s[:i + 2] + '1' + s[i + 3:]
			t += 1
	return t
for _ in range(int(input())):
	print(correct(input()))


t = int(input())
while t > 0:
	t = t - 1
	s = input()
	s = list(s)
	l = len(s)
	count = 0
	if l == 0 or l == 1:
		print(0)
		continue
	if l == 2 and s[0] == s[1]:
		print(1)
		continue
	elif l == 2 and s[0] != s[1]:
		print(0)
		continue
	if s[0] == s[1]:
		count += 1
		s[1] = 0
	for i in range(1, l - 1):
		if s[i - 1] == s[i + 1] and s[i - 1] != 0:
			count += 1
			s[i + 1] = 0
		if s[i] == s[i + 1] and s[i] != 0:
			count += 1
			s[i + 1] = 0
	print(count)


import sys
input = sys.stdin.readline

def solution():
	S = list(input().rstrip())
	n = len(S)
	ans = 0
	for i in range(1, n):
		if S[i] == S[i - 1]:
			S[i] = '-'
			ans += 1
		elif i > 1 and S[i] == S[i - 2]:
			S[i] = '-'
			ans += 1
	print(ans)
T = int(input())
for _ in range(T):
	solution()


t = int(input())
for i in range(t):
	orpheus = input()
	dp = []
	result = 0
	for j in range(len(orpheus)):
		if j > 1 and orpheus[j] == orpheus[j - 2] and (not dp[len(dp) - 2]):
			result += 1
			dp.append(True)
			continue
		elif j > 0 and orpheus[j] == orpheus[j - 1] and (not dp[len(dp) - 1]):
			result += 1
			dp.append(True)
			continue
		dp.append(False)
	print(result)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = list(input())[:-1]
	ans = 0
	i = 0
	while True:
		if i >= len(s):
			break
		curr = s[i]
		if curr == '-':
			i += 1
			continue
		if i + 1 < len(s) and s[i + 1] == curr:
			ans += 1
			s[i + 1] = '-'
		if i + 2 < len(s) and s[i + 2] == curr:
			ans += 1
			s[i + 2] = '-'
		else:
			i += 1
		if i >= len(s):
			break
	print(ans)


from sys import stdin
t = int(stdin.readline())
for k in range(t):
	b = stdin.readline()[:-1]
	n = len(b)
	s = []
	for i in b:
		s.append(i)
	counter = 0
	i = 1
	prev = 0
	while i < n:
		if s[i] == s[i - 1]:
			counter += 1
			s[i] = '-2'
		elif i >= 2 and s[i] == s[i - 2]:
			s[i] = '-1'
			counter += 1
		i += 1
	print(counter)


def removePalindro(s):
	sum = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 2] and i - 2 >= 0 or (s[i] == s[i - 1] and i - 1 >= 0):
			s = s[:i] + '_' + s[i + 1:]
			sum += 1
	return sum
n = int(input())
sol = ''
for i in range(n):
	s = input()
	sol += str(removePalindro(s)) + '\n'
print(sol)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import math

def nCk(n, k):
	res = 1
	for i in range(1, k + 1):
		res = res * (n - i + 1) // i
	return res
for _ in range(int(input())):
	s = list(input())
	n = len(s)
	cnt = 0
	al = 'qwertyuiopasdfghjklmnbvcxz'
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			tt = ''
			tt += s[i - 1]
			if i + 1 < n:
				tt += s[i + 1]
			if i + 2 < n:
				tt += s[i + 2]
			if i - 2 >= 0:
				tt += s[i - 2]
			for j in al:
				if j not in tt:
					s[i] = j
			cnt += 1
		elif i - 2 >= 0 and s[i] == s[i - 2]:
			tt = ''
			tt += s[i - 2]
			if i + 1 < n:
				tt += s[i + 1]
			if i + 2 < n:
				tt += s[i + 2]
			if i - 1 >= 0:
				tt += s[i - 1]
			for j in al:
				if j not in tt:
					s[i] = j
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	s = input()
	n = len(s)
	ans = 0
	used = [False] * n
	for i in range(1, n):
		temp = False
		if i == 1:
			if s[i] == s[i - 1] and (not used[i - 1]):
				temp = True
		else:
			if s[i] == s[i - 1] and (not used[i - 1]):
				temp = True
			if s[i] == s[i - 2] and (not used[i - 2]):
				temp = True
		used[i] = temp
		ans += int(temp)
	print(ans)


t = int(input())
ans_list = []
for i in range(t):
	poem = input()
	new_constructed = ''
	for i in range(len(poem)):
		if i == 0:
			new_constructed += poem[i]
		elif i == 1:
			if poem[i] == new_constructed[i - 1]:
				new_constructed += '*'
			else:
				new_constructed += poem[i]
		elif poem[i] == new_constructed[i - 1]:
			new_constructed += '*'
		elif poem[i] == new_constructed[i - 2]:
			new_constructed += '*'
		else:
			new_constructed += poem[i]
	ans_list.append(new_constructed.count('*'))
	new_constructed = ''
for i in ans_list:
	print(i)


for _ in range(int(input())):
	a = list(input())
	b = 0
	for i in range(1, len(a)):
		if i >= 2 and a[i] == a[i - 2] or a[i] == a[i - 1]:
			b += 1
			a[i] = 'A'
	print(b)


T = int(input())
for j in range(0, T):
	palString = list(input())
	n = len(palString)
	totalOperations = 0
	for i in range(0, n):
		if i > 0:
			if palString[i] == palString[i - 1] and palString[i] != '$':
				palString[i] = '$'
				totalOperations += 1
		if i > 1:
			if palString[i] == palString[i - 2] and palString[i] != '$':
				palString[i] = '$'
				totalOperations += 1
	print(totalOperations)


t = int(input())
for i in range(t):
	s = input()
	ind = 0
	l = len(s)
	c = 0
	while True:
		if ind > l - 1:
			break
		elif ind + 3 < l and s[ind] != s[ind + 1] and (s[ind] == s[ind + 2]) and (s[ind] != s[ind + 3]) and (s[ind + 1] != s[ind + 2]) and (s[ind + 1] == s[ind + 3]) and (s[ind + 2] != s[ind + 3]):
			c += 2
			ind += 4
		elif ind + 2 < l and s[ind] == s[ind + 1] and (s[ind] == s[ind + 2]):
			c += 2
			ind += 3
		elif ind + 1 < l and s[ind] == s[ind + 1]:
			c += 1
			ind += 2
		elif ind + 2 < l and s[ind] != s[ind + 1] and (s[ind] == s[ind + 2]):
			c += 1
			ind += 3
		else:
			ind += 1
	print(c)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		s = list(rs())
		t = 0
		op = 0
		for i in range(len(s)):
			t += 1
			t = t % 10
			if i >= 1:
				if s[i] == s[i - 1]:
					op += 1
					s[i] = str(t)
					t += 1
					t = t % 10
			if i >= 2:
				if s[i] == s[i - 2]:
					op += 1
					s[i] = str(t)
					t += 1
					t = t % 10
		print(op)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from queue import PriorityQueue
from queue import Queue
import math
from collections import defaultdict
import sys
import operator as op
from functools import reduce
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	s = input()
	n = len(s)
	if n == 1:
		print(0)
	elif n == 2:
		if s[0] == s[1]:
			print(1)
		else:
			print(0)
	else:
		cnt = 0
		ar = [False] * n
		if s[0] == s[1]:
			ar[1] = True
			cnt += 1
		for k in range(2, n):
			if s[k] == s[k - 1] and ar[k - 1] == False:
				ar[k] = True
				cnt += 1
			if s[k] == s[k - 2] and ar[k - 2] == False:
				ar[k] = True
				cnt += 1
		print(cnt)


for _ in range(int(input())):
	poem = list(input())
	ans1 = 0
	index = 1
	if len(poem) > 2:
		while index <= len(poem) - 2:
			if poem[index] == poem[index + 1] and poem[index] == poem[index - 1]:
				ans1 += 2
				index += 3
			elif poem[index] == poem[index - 1]:
				ans1 += 1
				poem[index] = str(index)
				index += 1
			elif poem[index] == poem[index + 1]:
				ans1 += 1
				poem[index + 1] = str(index)
				index += 1
			elif poem[index - 1] == poem[index + 1]:
				ans1 += 1
				poem[index + 1] = str(index)
				index += 1
			else:
				index += 1
		if index == len(poem) - 1:
			if poem[-1] == poem[-2]:
				ans1 += 1
	elif len(poem) == 2:
		if poem[0] == poem[1]:
			ans1 += 1
	print(ans1)