#K70782. Minimum Moves to Uniform String

    ID: 33385 Type: Default 1000ms 256MiB

Minimum Moves to Uniform String

Minimum Moves to Uniform String

You are given a non-empty string S consisting of lowercase letters. In one move, you can change any character of the string to any other character. Your task is to determine the minimum number of moves required to make all characters in S identical.

The optimal strategy is to change all characters except for the most frequent one. Mathematically, if the frequency of the most frequent character is \(f_{max}\) and \(|S|\) is the length of the string, the minimum number of moves is given by:

[ \text{moves} = |S| - \max_{c \in S} f(c) ]

For example, for the string "abac", the most frequent character is 'a' which appears 2 times, so the minimum moves required is \(4 - 2 = 2\).

inputFormat

The input is read from stdin and consists of multiple test cases. The first line contains an integer T representing the number of test cases. Each of the following T lines contains a single string S.

outputFormat

For each test case, output the minimum number of moves on a separate line to convert the string into a uniform string (all characters are the same), written to stdout.

## sample
2
abac
aaaa
2

0

</p>