1.3 Alicent and Integers
(RankList for this Question)
Score: 30pts
Time Limit: 5.00 sec
Alicent is fond of huge integers. She gives you an integer (b) that contains p digits. She also gives you another sequence of digits (s) of length q. You can select any position i (1 ≤ i ≤ p) in b and replace the digit in the selected position i with s[j] (1 ≤ j ≤ q). Each element in s can be used only once in the replacing operation.

Now you have to perform such a series of replacements, that the given number b gets maximum value.

Constraints
1 <= t <= 10
1 <= p <= 100
1 <= q <= 100

Input Format
t (No. of test cases)
For each test case-
b (Integer b with length p)
s (Sequence of digits s with length q)

b doesn’t contain leading zeroes.

Output Format
For each test case-
Print maximum value that can be obtained after a series of replacements.

Example 1
Input:
2
123
98
997
333

Output:
983
997

Explanation:
In the first case, 1 and 2 in b are replaced with 9 and 8 from s respectively.

In the second case, no digit in s can increase the value of b. Hence 997 is the answer.

Log In to solve the Question