#K46957. Minimum Deletions to Make Alternating String

    ID: 28091 Type: Default 1000ms 256MiB

Minimum Deletions to Make Alternating String

Minimum Deletions to Make Alternating String

Given a string s, your task is to determine the minimum number of deletions required to transform the string into one where no two adjacent characters are the same. In other words, ensure that the string becomes an alternating sequence.

Consider the string ss. You need to remove as few characters as possible such that for every index ii (1i<s1 \leq i < |s|), sisi+1s_i \neq s_{i+1}.

For example, if s=AAAAs = \texttt{AAAA}, then you need to delete 3 characters to get \texttt{A}. Similarly, for s=ABABABABs = \texttt{ABABABAB}, the string is already alternating and requires no deletions.

inputFormat

The input is read from standard input (stdin) and is structured as follows:

(T) -- the number of test cases (an integer).
Following this, there are (T) lines, each containing a single string (s).

For each test case, you need to compute the minimum number of deletions required.

outputFormat

For each test case, print on a new line the minimum number of deletions required to make the string alternating. The output should be sent to standard output (stdout).## sample

3
AAAA
BBBBB
ABABABAB
3

4 0

</p>