Given a string of lowercase alphabets and a number k, the task is to print the minimum value of the string after removal of ‘k’ characters. The value of a string is defined as the sum of squares of the count of each distinct character. Example:
Input : str = abccc, K = 1 Output : 6
We remove c to get the value as 11 + 11 + 22
First line consists of T test cases. First line of every test case consists of String s. Second line of every test case consists of a integer K.
Single line output, Print the minimum square sum.