#K36327. Minimum Cost to Palindrome

    ID: 25730 Type: Default 1000ms 256MiB

Minimum Cost to Palindrome

Minimum Cost to Palindrome

Given a string composed only of characters 'A' and 'B', your task is to determine the minimum number of modifications required to transform the string into a palindrome. A modification involves changing a character from 'A' to 'B' or from 'B' to 'A'.

The cost to convert a string \(s = s_0s_1\dots s_{n-1}\) of length \(n\) into a palindrome is defined as:

$$ \text{cost} = \sum_{i=0}^{\lfloor\frac{n-1}{2}\rfloor} \mathbf{1}_{\{s_i \neq s_{n-i-1}\}} $$

For each test case, output the minimum cost required.

inputFormat

The input will be read from standard input (stdin) and is formatted as follows:

  • The first line contains an integer \(T\), representing the number of test cases.
  • The following \(T\) lines each contain a string composed exclusively of the characters 'A' and 'B'.

Each test case is processed independently.

outputFormat

For each test case, output one integer on a new line - the minimum cost required to convert the string into a palindrome. The output should be written to standard output (stdout).

## sample
3
AAB
ABBA
ABBABB
1

0 2

</p>