#P1389C. Good String
Good String
Description
Let's call left cyclic shift of some string as string .
Analogically, let's call right cyclic shift of string as string .
Let's say string is good if its left cyclic shift is equal to its right cyclic shift.
You are given string which consists of digits 0–9.
What is the minimum number of characters you need to erase from to make it good?
The first line contains single integer () — the number of test cases.
Next lines contains test cases — one per line. The first and only line of each test case contains string (). Each character is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed .
For each test case, print the minimum number of characters you need to erase from to make it good.
Input
The first line contains single integer () — the number of test cases.
Next lines contains test cases — one per line. The first and only line of each test case contains string (). Each character is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed .
Output
For each test case, print the minimum number of characters you need to erase from to make it good.
Note
In the first test case, you can erase any characters, for example, the -st, the -rd, and the -th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string is already good.