

You are given a string S of length N, and a non-negative integer K, your task is to find the minimum sum of squares of unique character counts in the given string S after removing K characters.
Note:
1) The string contains only lowercase English letters.
2) The length of the string is at least 1.
3) It is guaranteed that K <= N.
4) Let S = aab, character count for a is 2 and that of b is 1. So, the sum of squares will be 2^2 + 1^2 = 5.
The first line of the input contains an integer T denoting the number of test cases.
The first line of each test case contains two space-separated integers, N and K, as described in the problem statement.
The second line of each test case contains a string S of length N.
Output Format:
For each test case print in a new line, an integer denoting the minimum sum of squares of unique character counts after removing K characters.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 20
1 <= N <= 10^4
1 <= K <= N
Time Limit: 1sec
1
5 1
aabac
6
Remove one ‘a’ from the string let us assume we remove 1st a, string becomes abac. So, the answer we get is 2^2 + 1^2 + 1^2 = 6. If we remove any other character than a let say b, so the answer is 3^2 + 0^2 + 1^2 = 10, which is not the minimum.
1
5 3
dabaa
2
Remove three ‘a’ from the string, string becomes db. So, the answer we get is 0^2 + 1^2 + 1^2 = 2. Another possible solution is to remove two ‘a’ and one ‘b’.
Select a subset of size K and remove these characters from the string which are in the subset.
O(2^N * N), where N is the length of the string and K is the number of characters to be removed.
2N for making the subset and after forming the subset we need to traverse the string again for the frequency array.
O(K), where N is the length of the string and K is the number of characters to be removed.
We are storing indices of a particular subset of size K, so extra space of k is required.