The Little Elephant loves lucky strings. Everybody knows that the lucky string is a string of digits that contains only the lucky digits 4 and 7. For example, strings "47", "744", "4" are lucky while "5", "17", "467" are not.

The Little Elephant has the strings A and B of digits. These strings are of equal lengths, that is |A| = |B|. He wants to get some lucky string from them. For this he performs the following operations. At first he arbitrary reorders digits of A. Then he arbitrary reorders digits of B. After that he creates the string C such that its i-th digit is the maximum between the i-th digit of A and the i-th digit of B. In other words, C[i] = max{A[i], B[i]} for i from 1 to |A|. After that he removes from C all non-lucky digits saving the order of the remaining (lucky) digits. So C now becomes a lucky string. For example, if after reordering A = "754" and B = "873", then C is at first "874" and then it becomes "74".

The Little Elephant wants the resulting string to be as lucky as possible. The formal definition of this is that the resulting string should be the lexicographically greatest possible string among all the strings that can be obtained from the given strings A and B by the described process.

Notes
|A| denotes the length of the string A.
A[i] denotes the i-th digit of the string A. Here we numerate the digits starting from 1. So 1 ≤ i ≤ |A|.
The string A is called lexicographically greater than the string B if either there exists some index i such that A[i] > B[i] and for each j < i we have A[j] = B[j], or B is a proper prefix of A, that is, |A| > |B| and first |B| digits of A coincide with the corresponding digits of B.

------ Input ------ 

The first line of the input contains a single integer T, the number of test cases. T test cases follow. Each test case consists of two lines. The first line contains the string A. The second line contains the string B.

------ Output ------ 

For each test case output a single line containing the answer for the corresponding test case. Note, that the answer can be an empty string. In this case you should print an empty line for the corresponding test case.

------ Constraints ------ 

1 ≤ T ≤ 10000
1 ≤ |A| ≤ 20000

|A| = |B|

Each character of A and B is a digit.

Sum of |A| across all the tests in the input does not exceed 200000.

----- Sample Input 1 ------ 
4
4
7
435
479
7
8
1675475
9756417
----- Sample Output 1 ------ 
7
74

777744
----- explanation 1 ------ 

Case 1. In this case the only possible string C we can get is "7" and it is the lucky string.

Case 2. If we reorder A and B as A = "543" and B = "749" the string C will be at first "749" and then becomes "74". It can be shown that this is the lexicographically greatest string for the given A and B.

Case 3. In this case the only possible string C we can get is "8" and it becomes and empty string after removing of non-lucky digits.

Case 4. If we reorder A and B as A = "7765541" and B = "5697714" the string C will be at first "7797744" and then becomes "777744". Note that we can construct any lexicographically greater string for the given A and B since we have only four "sevens" and two "fours" among digits of both strings A and B as well the constructed string "777744".

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Constructive algorithms

Data structures

Ad-hoc


Solutions:
t = input()
t = int(t)
while t:
	A = input()
	A = list(A)
	B = input()
	B = list(B)
	A = list(map(int, A))
	B = list(map(int, B))
	larger_7_in_A = 0
	seven_in_A = 0
	four_in_A = 0
	smaller_4_in_A = 0
	in_between_A = 0
	for i in A:
		if i < 4:
			smaller_4_in_A = smaller_4_in_A + 1
		elif i == 4:
			four_in_A = four_in_A + 1
		elif i < 7:
			in_between_A = in_between_A + 1
		elif i == 7:
			seven_in_A = seven_in_A + 1
		else:
			larger_7_in_A = larger_7_in_A + 1
	larger_7_in_B = 0
	seven_in_B = 0
	four_in_B = 0
	smaller_4_in_B = 0
	in_between_B = 0
	for i in B:
		if i < 4:
			smaller_4_in_B = smaller_4_in_B + 1
		elif i == 4:
			four_in_B = four_in_B + 1
		elif i < 7:
			in_between_B = in_between_B + 1
		elif i == 7:
			seven_in_B = seven_in_B + 1
		else:
			larger_7_in_B = larger_7_in_B + 1
	answer = []
	if seven_in_A <= in_between_B:
		answer.extend('7' * seven_in_A)
		in_between_B = in_between_B - seven_in_A
		seven_in_A = 0
	if seven_in_A > in_between_B:
		answer.extend('7' * in_between_B)
		seven_in_A = seven_in_A - in_between_B
		in_between_B = 0
	if seven_in_A <= smaller_4_in_B:
		answer.extend('7' * seven_in_A)
		smaller_4_in_B = smaller_4_in_B - seven_in_A
		seven_in_A = 0
	if seven_in_A > smaller_4_in_B:
		answer.extend('7' * smaller_4_in_B)
		seven_in_A = seven_in_A - smaller_4_in_B
		smaller_4_in_B = 0
	if seven_in_A <= four_in_B:
		answer.extend('7' * seven_in_A)
		four_in_B = four_in_B - seven_in_A
		seven_in_A = 0
	if seven_in_A > four_in_B:
		answer.extend('7' * four_in_B)
		seven_in_A = seven_in_A - four_in_B
		four_in_B = 0
	if seven_in_A <= seven_in_B:
		answer.extend('7' * seven_in_A)
		seven_in_B = seven_in_B - seven_in_A
		seven_in_A = 0
	if seven_in_A > seven_in_B:
		answer.extend('7' * seven_in_B)
		seven_in_A = seven_in_A - seven_in_B
		seven_in_B = 0
	if seven_in_B <= in_between_A:
		answer.extend('7' * seven_in_B)
		in_between_A = in_between_A - seven_in_B
		seven_in_B = 0
	if seven_in_B > in_between_A:
		answer.extend('7' * in_between_A)
		seven_in_B = seven_in_B - in_between_A
		in_between_A = 0
	if seven_in_B <= smaller_4_in_A:
		answer.extend('7' * seven_in_B)
		smaller_4_in_A = smaller_4_in_A - seven_in_B
		seven_in_B = 0
	if seven_in_B > smaller_4_in_A:
		answer.extend('7' * smaller_4_in_A)
		seven_in_B = seven_in_B - smaller_4_in_A
		smaller_4_in_A = 0
	if seven_in_B <= four_in_A:
		answer.extend('7' * seven_in_B)
		four_in_A = four_in_A - seven_in_B
		seven_in_B = 0
	if seven_in_B > four_in_A:
		answer.extend('7' * four_in_A)
		seven_in_B = seven_in_B - four_in_A
		four_in_A = 0
	if seven_in_B <= seven_in_A:
		answer.extend('7' * seven_in_B)
		seven_in_A = seven_in_A - seven_in_B
		seven_in_B = 0
	if seven_in_B > seven_in_A:
		answer.extend('7' * seven_in_A)
		seven_in_B = seven_in_B - seven_in_A
		seven_in_A = 0
	if four_in_B <= smaller_4_in_A:
		answer.extend('4' * four_in_B)
		smaller_4_in_A = smaller_4_in_A - four_in_B
		four_in_B = 0
	if four_in_B > smaller_4_in_A:
		answer.extend('4' * smaller_4_in_A)
		four_in_B = four_in_B - smaller_4_in_A
		smaller_4_in_A = 0
	if four_in_B <= four_in_A:
		answer.extend('4' * four_in_B)
		four_in_A = four_in_A - four_in_B
		four_in_B = 0
	if four_in_B > four_in_A:
		answer.extend('4' * four_in_A)
		four_in_B = four_in_B - four_in_A
		four_in_A = 0
	if four_in_A <= smaller_4_in_B:
		answer.extend('4' * four_in_A)
		smaller_4_in_B = smaller_4_in_B - four_in_A
		four_in_A = 0
	if four_in_A > smaller_4_in_B:
		answer.extend('4' * smaller_4_in_B)
		four_in_A = four_in_A - smaller_4_in_A
		smaller_4_in_B = 0
	if four_in_A <= four_in_B:
		answer.extend('4' * four_in_A)
		four_in_B = four_in_B - four_in_A
		four_in_A = 0
	if four_in_A > four_in_B:
		answer.extend('4' * four_in_B)
		four_in_A = four_in_A - four_in_A
		four_in_B = 0
	k = ''
	for i in answer:
		k = k + i
	t = t - 1
	print(k)


for _ in range(int(input())):
	a = input()
	b = input()
	a7 = 0
	a4 = 0
	a74 = 0
	a40 = 0
	b7 = 0
	b4 = 0
	b74 = 0
	b40 = 0
	for i in range(len(a)):
		if a[i] == '7':
			a7 += 1
		elif a[i] == '4':
			a4 += 1
		elif '7' > a[i] > '4':
			a74 += 1
		elif a[i] < '4':
			a40 += 1
		if b[i] == '7':
			b7 += 1
		elif b[i] == '4':
			b4 += 1
		elif '7' > b[i] > '4':
			b74 += 1
		elif b[i] < '4':
			b40 += 1
	m = min(a7, b74)
	s7 = m
	a7 -= m
	b74 -= m
	m = min(a7, b40)
	s7 += m
	a7 -= m
	b40 -= m
	m = min(a7, b4)
	s7 += m
	a7 -= m
	b4 -= m
	m = min(b7, a74)
	s7 += m
	b7 -= m
	a74 -= m
	m = min(b7, a40)
	s7 += m
	b7 -= m
	a40 -= m
	m = min(b7, a4)
	s7 += m
	b7 -= m
	a4 -= m
	m = min(a4, b40)
	s4 = m
	a4 -= m
	b40 -= m
	m = min(b4, a40)
	s4 += m
	b4 -= m
	a40 -= m
	s7 += min(a7, b7)
	s4 += min(a4, b4)
	print('7' * s7 + '4' * s4)