#C2828. Gem Collection Value Calculation

    ID: 46187 Type: Default 1000ms 256MiB

Gem Collection Value Calculation

Gem Collection Value Calculation

In this problem, you are given an integer t representing the number of test cases. Each test case consists of a string where each character represents a type of gem in Rita's collection. For each test case, you need to calculate the total value V using the formula: for each distinct gem type with frequency c, its contribution is given by $$c \times (c+1)$$. The total value is the sum of contributions of all gem types.

Your task is to compute and output the total value for each test case. Each output should be printed on a new line.

inputFormat

The input is given via stdin:

  • The first line contains a single integer t denoting the number of test cases.
  • Each of the next t lines contains a string representing the collection of gems. Each character in the string represents a gem type.

outputFormat

For each test case, print a single integer – the total value of the gem collection – on a new line to stdout.

## sample
1
aaaa
20

</p>