Scripting Machine

oorpib STP Coding Test 31 Dec 20...
Limits 1s, 512 MB

Nahid has his own printing press, “Desher Khobor” . He feels that words on their own simply aren't beautiful enough. So, he wishes to make a Super machine. Now what does this machine do?

The machine aims to make words as beautiful as they can be by making a word as lexicographically small as possible. Nahid, being the resourceful person he is, has a reserve string from which we can choose characters that will replace characters in the original word that machine wishes to transform.

Keep in mind that once you have used a letter in the reserve string, it is removed from the reserve.
As Nahid is busy with other works, it's your task to take care of programming the machine .

Note that you cannot modify the original order of the letters in the word that has to be transformed. You can only replace its letters with those in the reserve.

Input

The first line of input contains T. T test cases follow.
Each test case has 2 lines.

The first line of each test case has the word W, that has to be transformed.
The second line of each test case has a reserve R from which we will pick letters.

Output

The output should contain T lines with the answer to each test on a new line.
Print a word P which is the lexicographically smallest that can be obtained on replacing letters of W with letters from R.

Sample

InputOutput
3
bbbb
aaa
zxewya
abcd
ac
zzzb
aaab
abcdya
ab

In the first test case, we have 3 a' s , so we simply replace the first 3 letters of the word.

Submit

Login to submit.

Statistics

87% Solution Ratio
sagarthecoderEarliest, Dec '20
wasimur_01Fastest, 0.0s
MursaleenLightest, 131 kB
aumit_seShortest, 426B
Toph uses cookies. By continuing you agree to our Cookie Policy.