#C6333. Minimum Operations to Balance String

    ID: 50082 Type: Default 1000ms 256MiB

Minimum Operations to Balance String

Minimum Operations to Balance String

You are given a string s consisting of lowercase English letters. In one operation, you can change any character in the string to any other lowercase letter. Your goal is to transform the string into a balanced string, where every character is the same.

The minimum number of operations needed is given by the formula:

$$ \text{operations} = n - \max_{c}(\text{count}(c) )$$

Here, n is the length of the string and \(\text{count}(c)\) denotes the frequency of character \(c\) in the string. For each test case, compute and output this minimum number of operations.

inputFormat

The input is read from standard input (stdin) and has the following format:

The first line contains an integer t (1 ≤ t ≤ 105), representing the number of test cases.
Each of the following t lines contains a non-empty string s consisting only of lowercase English letters (1 ≤ |s| ≤ 105).

outputFormat

For each test case, output a single integer on a new line representing the minimum number of operations required to make the string balanced.

The output should be written to standard output (stdout).

## sample
3
aabb
abcde
aaabb
2

4 2

</p>