|All-time Popular Problems|
|Inorder Successor in BST|
|Depth First Traversal for a Graph|
|Delete nodes having greater value on right|
|Column name from a given column number|
|Search an Element in an array|
|Diameter of Binary Tree|
|Get minimum element from stack|
|Subset Sum Problem|
|Reverse words in a given string|
|Reverse a linked list|
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 sum of squares of count of each distinct character. For example consider the string “saideep”, here frequencies of characters are s-1, a-1, i-1,e-2, d-1, p-1 and value of the string is 1^2 + 1^2 + 1^2 + 1^2 + 1^1 + 2^2 = 9.
The first line of input contains the number T denoting the no of test cases . Then T test cases follow. Each test case contains two lines.The first line of each test case contains a string str. The second line of each test case consist of an integer k .
The output for each test case will be an integer denoting the min possible value of the string.