## Pages

### Arjit and Printing Press : HackerEarth Problem Solution

Arjit has his own printing press, Bainik Dhaskar (BD). He feels that words on their own simply aren't beautiful enough. So, he wishes to make a Super Manuscript (SM) machine. Now what does this machine do?

The SM machine aims to make words as beautiful as they can be by making a word as lexicographically small as possible. Arjit, 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 BD's SM 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 Arjit is busy with other work at BD, it's your work to take care of programming SM :)

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.

Constraints:

$1\le T\le 10$
$1\le |W|\le 10$ $4$
$1\le |R|\le 10$ $4$

Sample Input

3

bbbb

aaa

zxewya

abcd

ac

zzzb

Sample Output

aaab

abcdya

ab

Explanation

In the first test case, we have $3$ ${a}^{\prime }s$, so we simply replace the first $3$ letters of the word.
In the second test case, again we just replace the first $4$ letters with ${}^{\prime }{a}^{\prime }{,}^{\prime }{b}^{\prime }{,}^{\prime }{c}^{\prime }$ and ${}^{\prime }{d}^{\prime }$.
In the third case, ${}^{\prime }{b}^{\prime }$ is lexicographically smaller than ${}^{\prime }{c}^{\prime }$, so ${}^{\prime }a{c}^{\prime }$ becomes ${}^{\prime }a{b}^{\prime }$.

C++ Implementation:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
int T;
char *s,*r;
cin>>T;
while(T--)
{
s = (char*)malloc(sizeof(char)*10000);
r = (char*)malloc(sizeof(char)*10000);
cin>>s>>r;
sort(r,r+strlen(r));
for(int i=0,j=0;s[i]&&r[j];i++)
{
if(r[j]<s[i])
s[i] = r[j++];
}
cout<<s<<endl;
}
return 0;
}