407328: GYM102766 B Singhal and Equality

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Singhal and Equalitytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

If you want to practice topicwise questions in the ladder way like a2oj , do register on my site http://codedigger.tech after the contest. Here you will get Handpicked Topicwise Questions from codeforces, codechef, uva and spoj for your better practice. Best of Luck.

Singhal loves Equality. He has a string $$$S$$$ consisting of lowercase English Letters.

He wants to equalize the frequency of all distinct characters in his string $$$S$$$. He can do the following operation any number of times: pick any single character in the string and replace with another lowercase English alphabet.

He wants to perform minimum number of operations to equalize the frequency of distinct characters.

Frequency of a character is number of times it appear in the string.

Input

The first line contains a single integer $$$t (1 \le t \le 10^5)$$$ — the number of test cases in the input. Then $$$t$$$ test cases follow.

Each query contains a single string consisting of lowercase English letters $$$S (1 \le |S| \le 10^5)$$$. $$$|S|$$$ is the length of the string.

It is guaranteed that the total sum of $$$|S|$$$ is at most $$$10^5$$$.

Output

Print $$$t$$$ answers to the test cases. Each answer must be consisting of single integer — the minimum number of operations required to equalize the frequency of distinct characters of string.

ExampleInput
6
aba
abba
abbc
abbbc
codedigger
codealittle
Output
1
0
1
2
2
3
Note

In the first query — We can replace letter $$$b \to a$$$ to form aaa. Now frequency of all distinct character is same i.e. $$$3$$$ or another possibility is replace one $$$a \to c$$$ to form abc. In this case frequency is $$$1$$$.

In the second query — Frequency of all distinct character is Same i.e. $$$2$$$. No need to apply operation.

加入题单

上一题 下一题 算法标签: