시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB21116715279.167%

문제

Define the complexity of a string to be the number of distinct letters in it. For example, the string string has complexity 6 and the string letter has complexity 4.

You like strings which have complexity either 1 or 2. Your friend has given you a string and you want to turn it into a string that you like. You have a magic eraser which will delete one letter from any string. Compute the minimum number of times you will need to use the eraser to turn the string into a string with complexity at most 2.

입력

The first line of input contains a positive integer n. Each of the following n lines contains a single string of at most 100 lowercase ASCII letters (‘a’-‘z’).

출력

For each input string print, on a single line, the minimum number of times you need to use the eraser.

예제 입력 1

5
string
letter
aaabbb
aaabbbccc
uncopyrightable

예제 출력 1

4
2
0
3
13