#K16296. Minimum Operations to Create a Special String

    ID: 24547 Type: Default 1000ms 256MiB

Minimum Operations to Create a Special String

Minimum Operations to Create a Special String

You are given t test cases. For each test case, you are provided a non-empty string consisting of lowercase English letters. A string is called special if all characters in the string are identical.

In one operation, you can select all occurrences of one particular letter and convert them to any other letter. Formally, if a string has k distinct letters, you can transform it into a special string in k-1 operations by changing every letter except one chosen letter. For instance, the string aaabccc contains 3 distinct letters, so it can be transformed in 2 operations.

Your task is to determine, for each test case, the minimum number of operations required to convert the given string into a special string.

inputFormat

The first line contains an integer t (1 ≤ t ≤ 100), the number of test cases. Each of the following t lines contains a non-empty string s, consisting only of lowercase English letters. The length of each string is at most 1000.

outputFormat

For each test case, output a single integer representing the minimum number of operations needed to transform the string into a special string. Each answer should be printed on its own line.

## sample
1
a
0