#K70667. Letter Frequency Squares
Letter Frequency Squares
Letter Frequency Squares
You are given a list of words. For each word, compute the sum of the squares of the frequency of each letter. Formally, for a word (W), if a letter (c) appears (f(c)) times, then the answer is given by (\displaystyle\sum_{c\in W}f(c)^2). Note that the computation is case-sensitive: for example, 'A' and 'a' are considered distinct. An empty word should yield a result of 0.
inputFormat
The first line contains an integer (T) ((1 \le T \le 1000)), the number of test cases. Each of the following (T) lines contains one word (which may be empty) consisting only of English letters.
outputFormat
For each test case, output a single integer on a new line: the sum of the squares of the frequency of each letter in the given word.## sample
3
manuscript
mystery
cipher
10
9
6
</p>