| TheForces Round #21 (EDU-Forces) |
|---|
| Finished |
You are given a magic string $$$s$$$ that consists of lowercase Latin letters and an integer $$$k$$$ $$$(k \lt |s|)$$$.
You can do the following operation exactly once:
A magic string $$$y$$$ is said to be weaker that a magic string $$$z$$$ of the same length if at the leftmost position where the character inside $$$y$$$ and $$$z$$$ is different, the character inside $$$y$$$ appears earlier in the alphabet than the character inside $$$z$$$.
More formally, let $$$l$$$ be the leftmost position where the character inside $$$y$$$ and $$$z$$$ differs. Then, $$$y_l \lt z_l$$$. For example, the magic string $$$y =$$$ "codeforall" is weaker than the magic string $$$z =$$$ "codeforces" since the leftmost position where they differ is the $$$8$$$-th position and $$$y_8 =$$$ 'a' $$$ \lt $$$ 'c' $$$= z_8$$$.
Find the weakest possible string that you can achieve.
The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 10^5)$$$ — the number of test cases.
The only line for each test case contains a string $$$s$$$ consisting of lowercase Latin letters followed by an integer $$$k$$$ $$$(1 \leq k \lt |s| \leq 4 \cdot 10^5)$$$.
It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$4 \cdot 10^5$$$.
For each test case, output a string $$$x$$$ — the weakest magic string obtained after the operation.
5haiti 2ptlwqak 4amogus 2inthatpi 5icodeforces 1
hai pak agus ini codeforces
For the first test case, we can delete the segment $$$[4,5]$$$ to get the string "hai". Other strings we can obtain by deleting other segments are "hti" and "iti". From all the possible strings obtained, the weakest one is "hai".
For the fifth test case, it can be proven that we can get the weakest magic string by deleting the segment $$$[1,1]$$$.
| Name |
|---|


