cswork / OAOpen practice workspace

SalesforceOA #31

Minimal Operations

Estimated EasyJudge-ready

Topics (AI-labelled)StringsGreedy

For each lowercase English word, you may replace any character with any lowercase letter; find the minimum number of replacements needed so that all adjacent characters differ. Output the result for each word independently.

Input

The input gives the number of words n and n lines of words. The full original bounds are kept: 1≤n≤100, each word has length 2..100000, and the characters are a..z; no total-length constraint is added to shrink the input, so the total number of characters can reach 10000000.

Output

Output the minimum number of replacements for each word in input order, separated by spaces or newlines.

Example 1

Input:

3
add
boook
break

Output:

1 1 0

Example 2

Input:

5
ab
aab
abb
abab
abaaaba

Output:

0 1 1 0 1

Example 3

Input:

2
zz
zzzzzz

Output:

1 3

Example notes

The outputs of the three public examples are, in order: 1 1 0; 0 1 1 0 1; 1 3. They have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…