#K95227. Minimum Replacements to Balance String

    ID: 38817 Type: Default 1000ms 256MiB

Minimum Replacements to Balance String

Minimum Replacements to Balance String

You are given a string s consisting only of the characters 'a', 'b', and 'c'. A string is considered balanced if each character appears exactly \(\lfloor\frac{n}{3}\rfloor\) times, where \(n\) is the length of the string.

Your task is to determine the minimum number of character replacements required to transform the input string into a balanced string. In one replacement, you can change any character to one of the other two characters. It is guaranteed that the input strings have lengths that allow the definition (using floor division) to be applied.

The input consists of multiple test cases. For each test case, compute the minimum number of replacements needed and output the result.

inputFormat

The first line contains an integer \(t\) denoting the number of test cases. Each of the following \(t\) lines contains a non-empty string \(s\) composed solely of the characters 'a', 'b', and 'c'.

Input Format:

t
s1
s2
...
s_t

outputFormat

For each test case, output a single integer on a new line — the minimum number of replacements required to balance the string.

## sample
3
aabb
abcabc
aaabbbccc
2

0 0

</p>