CF1702D.Not a Cheap String

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Not a Cheap String

Let ss be a string of lowercase Latin letters. Its price is the sum of the indices of letters (an integer between 1 and 26) that are included in it. For example, the price of the string abca is 1+2+3+1=71+2+3+1=7.

The string ww and the integer pp are given. Remove the minimal number of letters from ww so that its price becomes less than or equal to pp and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string ww is less than or equal to pp, then nothing needs to be deleted and ww must be output.

Note that when you delete a letter from ww, the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.

Input

The first line of input contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases in the test. The following are descriptions of tt test cases.

Each case consists of two lines.

The first of them is the string ww, it is non-empty and consists of lowercase Latin letters. Its length does not exceed 21052\cdot10^5.

The second line contains an integer pp (1p52000001 \le p \le 5\,200\,000).

It is guaranteed that the sum of string lengths ww over all test cases does not exceed 21052 \cdot 10^5.

Output

Output exactly tt rows, the ii-th of them should contain the answer to the ii-th set of input data. Print the longest string that is obtained from ww by deleting letters such that its price is less or equal to pp. If there are several answers, then output any of them.

Note that the empty string  — is one of the possible answers. In this case, just output an empty string.

Samples

5
abca
2
abca
6
codeforces
1
codeforces
10
codeforces
100
aa
abc

cdc
codeforces

在线编程 IDE

建议全屏模式获得最佳体验