403176: GYM101061 E Playing with numbers

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Playing with numberstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

Folan and Eltan are brothers. However, as all brothers are, they always fight. One day their mom had to go to work, so she decided to give them a task to keep them busy while she is away.

She gave them two numbers S and N.

She told Folan that he has to delete exactly N digits from the number S, so that the resulting number is as small as possible.

Then, she told Eltan that he has to delete exactly N digits from the number S, so that the resulting number is as big as possible.

Folan and Eltan are ex ACMers. They decided to write a program to solve this problem, so they can go back to fighting again.

When their mom heard the evil plan, she decided to make the number S very big, and she may have added leading zeros to it.

The boys were really upset because they couldn't find a way to write a program that would solve this problem fast enough before their mom returns, so they asked for your help.

Can you help them with this program, so they can go back to fighting again?

Input

The first line of the input consists of a single integer t, the number of test cases. Each test case consists of two numbers S and N separated by a single space. where (0 ≤ S < 10100000) and it may contain leading zeros, and (0 ≤ N < |S|).

Note that |S| means the length of the number S.

Output

For each test case, print two lines.

The first line should contain the smallest number Folan can get after deleting exactly N digits from S.

The second line should contain the biggest number Eltan can get after deleting exactly N digits from S.

Please note that in case some of the leading zeros were not deleted, you have to print the resulting number with the remaining leading zeros.

ExampleInput
3
00123 2
00123 3
234714812741111111111111111111 4
Output
001
123
00
23
14812741111111111111111111
74812741111111111111111111

加入题单

算法标签: