#K33572. Alternating Lights

    ID: 25117 Type: Default 1000ms 256MiB

Alternating Lights

Alternating Lights

You are given a string representing a sequence of colored lights. Each light is either red (R) or blue (B). Your task is to determine the minimum number of changes required so that no two consecutive lights have the same color. In other words, for every valid index i, the condition \(lights_i \neq lights_{i+1}\) must hold.

One way to achieve this is to transform the given string into one of the two alternating patterns: one starting with R (i.e. R, B, R, B, ...) or one starting with B (i.e. B, R, B, R, ...). Compute the number of changes required for both cases and output the minimum of the two.

inputFormat

The first line of input contains a single integer T (1 ≤ T ≤ 104), representing the number of test cases.

Each of the next T lines contains a non-empty string consisting only of the characters R and B, representing the current configuration of lights.

outputFormat

For each test case, output a single integer on a new line — the minimum number of changes required so that no two consecutive lights have the same color.

## sample
1
RBRB
0

</p>