cswork / OAOpen practice workspace

VeriskOA #1

minimalOperations (Adjacent Duplicate Replacements)

Estimated EasyJudge-ready

Topics (AI-labelled)StringsGreedy

For each word, find the minimum number of character replacements so that no two adjacent characters are the same.

Input

The first line contains n (1≤n≤100); each of the next n lines is a lowercase word of length 2..100000.

Output

For each word, output one line with the minimum number of replacements.

Example 1

Input:

3
add
boook
break

Output:

1
1
0

Example notes

A linear-scan/dynamic-programming solution follows directly from the rules; the examples have been checked one by one against an independently built oracle.

Editorial

Loading solution…