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.

-----Example-----
Input:
4
4
7
435
479
7
8
1675475
9756417

Output:
7
74

777744

-----Explanation-----
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".

Difficulty: interview

Starter code:

Solutions:

t = int(input())

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j >= '7':
			if j > '7':
				agts += 1
			else:
				aseven += 1
		elif j >= '4':
			if j > '4':
				afts += 1
			else:
				afour += 1
		else:
			altf += 1
	
	for j in b:
		if j >= '7':
			if j > '7':
				bgts += 1
			else:
				bseven += 1
		elif j >= '4':
			if j > '4':
				bfts += 1
			else:
				bfour += 1
		else:
			bltf += 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven -= bfts;
		nseven += bfts;
		bfts = 0;
	else:
		bfts -= aseven;
		nseven += aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven -= afts;
		nseven += afts;
		afts = 0;
	else:
		afts -= bseven;
		nseven += bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven -= bltf;
		nseven += bltf;
		bltf = 0;
	else:
		bltf -= aseven;
		nseven += aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven -= altf;
		nseven += altf;
		altf = 0;
	else:
		altf -= bseven;
		nseven += bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven -= bfour;
		nseven += bfour;
		bfour = 0;
	else:
		bfour -= aseven;
		nseven += aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven -= afour;
		nseven += afour;
		afour = 0;
	else:
		afour -= bseven;
		nseven += bseven;
		bseven = 0;
	
	nseven += min(aseven,bseven)
	
	if afour > bltf:
		afour -= bltf;
		nfour += bltf;
		bltf = 0
	else:
		bltf -= afour;
		nfour += afour;
		afour = 0;
	
	if bfour > altf:
		bfour -= altf;
		nfour += altf;
		altf = 0
	else:
		altf -= bfour;
		nfour += bfour;
		bfour = 0;
	
	nfour += min(afour,bfour)
	
	print('7'*nseven + '4'*nfour)


t = int(input())

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j >= '7':
			if j > '7':
				agts = agts + 1
			else:
				aseven = aseven + 1
		elif j >= '4':
			if j > '4':
				afts = afts + 1
			else:
				afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j >= '7':
			if j > '7':
				bgts = bgts + 1
			else:
				bseven = bseven + 1
		elif j >= '4':
			if j > '4':
				bfts = bfts + 1
			else:
				bfour = bfour + 1
		else:
			bltf = bltf + 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	print('7'*nseven + '4'*nfour)


t = int(input())

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j >= '7':
			if j > '7':
				agts = agts + 1
			else:
				aseven = aseven + 1
		elif j >= '4':
			if j > '4':
				afts = afts + 1
			else:
				afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j >= '7':
			if j > '7':
				bgts = bgts + 1
			else:
				bseven = bseven + 1
		elif j >= '4':
			if j > '4':
				bfts = bfts + 1
			else:
				bfour = bfour + 1
		else:
			bltf = bltf + 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	print('%s%s' % ('7'*nseven, '4'*nfour))


t = int(input())

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j >= '7':
			if j > '7':
				agts = agts + 1
			else:
				aseven = aseven + 1
		elif j >= '4':
			if j > '4':
				afts = afts + 1
			else:
				afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j >= '7':
			if j > '7':
				bgts = bgts + 1
			else:
				bseven = bseven + 1
		elif j >= '4':
			if j > '4':
				bfts = bfts + 1
			else:
				bfour = bfour + 1
		else:
			bltf = bltf + 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	print('%s%s' % ('7'*nseven, '4'*nfour))


t = int(input())

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j >= '7':
			if j > '7':
				agts = agts + 1
			else:
				aseven = aseven + 1
		elif j >= '4':
			if j > '4':
				afts = afts + 1
			else:
				afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j >= '7':
			if j > '7':
				bgts = bgts + 1
			else:
				bseven = bseven + 1
		elif j >= '4':
			if j > '4':
				bfts = bfts + 1
			else:
				bfour = bfour + 1
		else:
			bltf = bltf + 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	print('7'*nseven + '4'*nfour)


t = int(input())

a = []
b = []

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j >= '7':
			if j > '7':
				agts = agts + 1
			else:
				aseven = aseven + 1
		elif j >= '4':
			if j > '4':
				afts = afts + 1
			else:
				afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j >= '7':
			if j > '7':
				bgts = bgts + 1
			else:
				bseven = bseven + 1
		elif j >= '4':
			if j > '4':
				bfts = bfts + 1
			else:
				bfour = bfour + 1
		else:
			bltf = bltf + 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	print('7'*nseven + '4'*nfour)


t = int(input())

a = []
b = []

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j > '7':
			agts = agts + 1
		elif j == '7':
			aseven = aseven + 1
		elif j > '4':
			afts = afts + 1
		elif j == '4':
			afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j > '7':
			bgts = bgts + 1
		elif j == '7':
			bseven = bseven + 1
		elif j > '4':
			bfts = bfts + 1
		elif j == '4':
			bfour = bfour + 1
		else:
			bltf = bltf + 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	print('7'*nseven + '4'*nfour)


t = int(input())

for i in range(0,t):
	a = input()
	b = input()
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j > '7':
			agts = agts + 1
		elif j == '7':
			aseven = aseven + 1
		elif j > '4':
			afts = afts + 1
		elif j == '4':
			afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j > '7':
			bgts = bgts + 1
		elif j == '7':
			bseven = bseven + 1
		elif j > '4':
			bfts = bfts + 1
		elif j == '4':
			bfour = bfour + 1
		else:
			bltf = bltf + 1
		
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	print('7'*nseven + '4'*nfour)


t = int(input())

# adict = [0]*10;
# bdict = [0]*10;

for i in range(0,t):
	a = input()
	b = input()
	
	# lena = len(a);
	
	agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
	
	for j in a:
		if j > '7':
			agts = agts + 1
		elif j == '7':
			aseven = aseven + 1
		elif j > '4':
			afts = afts + 1
		elif j == '4':
			afour = afour + 1
		else:
			altf = altf + 1
	
	for j in b:
		if j > '7':
			bgts = bgts + 1
		elif j == '7':
			bseven = bseven + 1
		elif j > '4':
			bfts = bfts + 1
		elif j == '4':
			bfour = bfour + 1
		else:
			bltf = bltf + 1
	
	# for j in range(0,10):
		# adict[j] = 0;
		# bdict[j] = 0;
	
	# for j in range(0,lena):
		# adict[int(a[j])] = adict[int(a[j])] + 1
		# bdict[int(b[j])] = bdict[int(b[j])] + 1
	
	# agts = adict[8] + adict[9]
	# bgts = bdict[8] + bdict[9]
	
	# aseven = adict[7]
	# bseven = bdict[7]
	
	# afts = adict[5] + adict[6]
	# bfts = bdict[5] + bdict[6]
	
	# afour = adict[4]
	# bfour = bdict[4]
	
	# altf = adict[0] + adict[1] + adict[2] + adict[3]
	# bltf = bdict[0] + bdict[1] + bdict[2] + bdict[3]
	
	nseven = 0
	nfour = 0
	
	if aseven > bfts:
		aseven = aseven - bfts;
		nseven = nseven + bfts;
		bfts = 0;
	else:
		bfts = bfts - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afts:
		bseven = bseven - afts;
		nseven = nseven + afts;
		afts = 0;
	else:
		afts = afts - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bltf:
		aseven = aseven - bltf;
		nseven = nseven + bltf;
		bltf = 0;
	else:
		bltf = bltf - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > altf:
		bseven = bseven - altf;
		nseven = nseven + altf;
		altf = 0;
	else:
		altf = altf - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	if aseven > bfour:
		aseven = aseven - bfour;
		nseven = nseven + bfour;
		bfour = 0;
	else:
		bfour = bfour - aseven;
		nseven = nseven + aseven;
		aseven = 0;
	
	if bseven > afour:
		bseven = bseven - afour;
		nseven = nseven + afour;
		afour = 0;
	else:
		afour = afour - bseven;
		nseven = nseven + bseven;
		bseven = 0;
	
	nseven = nseven + min(aseven,bseven)
	
	if afour > bltf:
		afour = afour - bltf;
		nfour = nfour + bltf;
		bltf = 0
	else:
		bltf = bltf - afour;
		nfour = nfour + afour;
		afour = 0;
	
	if bfour > altf:
		bfour = bfour - altf;
		nfour = nfour + altf;
		altf = 0
	else:
		altf = altf - bfour;
		nfour = nfour + bfour;
		bfour = 0;
	
	nfour = nfour + min(afour,bfour)
	
	if nseven + nfour > 0:
		print('7'*nseven + '4'*nfour)
	else:
		print()

def lucky10(X, Y):
	x, y = {4:0, 7:0}, {4:0, 7:0}
	X =list(map(int, X))
	Y =list(map(int,Y))
	x47, y47 = {4:0, 7:0}, {4:0, 7:0}
	for i in X:
		if i == 4:
			x47[4] += 1
		elif i == 7:
			x47[7] += 1
		elif i < 4:
			x[4] += 1
		elif i<7 and i>4:
			x[7] += 1
	for i in Y:
		if i == 4:
			y47[4] += 1
		elif i == 7:
			y47[7] += 1
		elif i < 4:
			y[4] += 1
		elif i<7 and i>4:
			y[7] += 1
	#print x47, y47, x, y
	n=""
	if x47[7] <= y[7]:
		n += '7'*x47[7]
		y[7] -= x47[7]
		x47[7] = 0
	elif x47[7] <= (y[7]+y[4]):
		n     += '7'*x47[7]
		y[4]  -= (x47[7]-y[7])
		y[7]   = 0
		x47[7] = 0
	elif x47[7] <= (y[7]+y[4]+y47[4]):
		y47[4] -= (x47[7]-(y[7]+y[4]))
		n += '7'*x47[7]
		x47[7] = 0
		y[7]=y[4]=0
	elif x47[7] <= (y[7]+y[4]+y47[4] + y47[7]):
		'''print "Debug value:", (x47[7]-(y[7]+y[4]+y47[4]))
		print y[7], " ", y[4], " ", y47[4]
		print y47[7]'''
		y47[7] -= (x47[7]-(y[7]+y[4]+y47[4]))
		n += '7'*x47[7]
		x47[7] = 0
		y[7]=y[4]=y47[4]=0
		#print "7 left in y", y47[7]
	else:
		n += '7'*(y[7]+y[4]+y47[4]+y47[7])		
		x47[7] = x47[7] - (y[7]+y[4]+y47[4]+y47[7])
		y[7]=y[4]=y47[4]=y47[7]=0

	if y47[7] <= x[7]:
		n += '7'*y47[7]
		x[7] -= y47[7]
		y47[7] = 0
	elif y47[7] <= (x[7]+x[4]):
		n += '7'*y47[7]
		x[4] -= (y47[7]-x[7])
		x[7]  =0
		y47[7] = 0
	elif y47[7] <= (x[7]+x[4]+x47[4]):		
		x47[4] -= (y47[7]-(x[7]+x[4]))
		n += '7'*y47[7]
		y47[7] = 0
		x[7]=x[4]=0
	elif y47[7] <= (x[7]+x[4]+x47[4] + x47[7]):		
		x47[7] -= (y47[7]-(x[7]+x[4]+x47[4]))
		n += '7'*y47[7]
		y47[7] = 0
		x[7]=x[4]=x47[4]=0
	else:
		n += '7'*(x[7]+x[4]+x47[4]+x47[7])		
		y47[7] -=  (x[7]+x[4]+x47[4]+x47[7])
		x[7]=x[4]=x47[4]=x47[7]=0

		####################4###############
	if x47[4] <= y[4]:
		n += '4'*x47[4]
		y[4] -= x47[4]
		x47[4] =0
	elif x47[4] <= (y[4]+y47[4]):
		n += '4'*x47[4]
		y47[4] -= (x47[4]-y[4])
		y[4]   = 0
		x47[4] = 0
	else:
		n += '4'*(y47[4]+y[4])		
		x47[4] -= (y47[4]+y[4])
		y47[4]=y[4]=0

	if y47[4] <= x[4]:
		n += '4'*y47[4]
		x[4] -= y47[4]
		y47[4] = 0
	elif y47[4] <= (x[4]+x47[4]):
		n += '4'*y47[4]
		x47[4] -= (y47[4]-x[4])
		x[4]   = 0
		y47[4] = 0
	else:
		n += '4'*(x47[4]+x[4])	
		y47[4] -= (x47[4]+x[4])
		x47[4]=x[4]=0
	return n
def io():
	t = int(input())
	st = ""
	while t>0:
		a = input()
		b = input()
		st += lucky10(a, b) + "\n"
		t-=1
	print(st)
io()


def inp():
    l = [0]*10
    for c in input():
        l[ord(c)-48] += 1
    return (l[0]+l[1]+l[2]+l[3], l[4], l[5]+l[6], l[7])

def go():
    a0,a4,a6,a7 = inp()
    b0,b4,b6,b7 = inp()
    r4 = r7 = 0
    m = min(b6, a7); r7 += m; b6 -= m; a7 -= m
    m = min(a6, b7); r7 += m; a6 -= m; b7 -= m
    m = min(b0, a7); r7 += m; b0 -= m; a7 -= m
    m = min(a0, b7); r7 += m; a0 -= m; b7 -= m
    m = min(b4, a7); r7 += m; b4 -= m; a7 -= m
    m = min(a4, b7); r7 += m; a4 -= m; b7 -= m
    m = min(a7, b7); r7 += m; a7 -= m; b7 -= m
    m = min(b0, a4); r4 += m; b0 -= m; a4 -= m
    m = min(a0, b4); r4 += m; a0 -= m; b4 -= m
    m = min(a4, b4); r4 += m; a4 -= m; b4 -= m
    print("7"*r7 + "4"*r4)

for t in range(eval(input())): go()


#!/usr/bin/python
#http://www.codechef.com/OCT12/problems/LUCKY10

import sys

def solve():
	a=sys.stdin.readline()
	b=sys.stdin.readline()

	def arrange(a,A):
		for i in a:
			if '0'<=i<='3':A[0]+=1
			elif i=='4':
				A[1]+=1
			elif i=='7':
				A[2]+=1
			elif '5'<=i<='6':A[3]+=1
	A,B=[0]*5,[0]*5
	arrange(a,A)
	arrange(b,B)

	ret=''
	ret=(min(A[2],B[3])+min(B[2],A[3]))*'7'

	A[2],B[2]=max(0,A[2]-B[3]),max(0,B[2]-A[3])
	t=min(A[1]+B[1],A[1]+A[0],B[1]+B[0])
	A[0]=A[1]+A[0]-t
	B[0]=B[1]+B[0]-t
	ret=ret+(min(A[2],B[0])+min(B[2],A[0]))*'7'
	A[2],B[2]=max(0,A[2]-B[0]),max(0,B[2]-A[0])
	ret=ret+(min(t,A[2])+min(t,B[2]))*'7'
	k=min(max(0,t-A[2]),max(0,t-B[2]))

	A[2],B[2]=max(0,A[2]-t),max(0,B[2]-t)
	ret=ret+min(A[2],B[2])*'7'+k*'4'

	print(ret)
	return 


t=int(input())
for i in range(t):
	solve()



#!/usr/bin/python
#http://www.codechef.com/OCT12/problems/LUCKY10

import sys

def solve():
	a=sys.stdin.readline()
	b=sys.stdin.readline()

	def arrange(a,A):
		for i in a:
			if '0'<=i<='3':A[0]+=1
			elif i=='4':
				A[1]+=1
			elif i=='7':
				A[2]+=1
			elif '5'<=i<='6':A[3]+=1
	A,B=[0]*5,[0]*5
	arrange(a,A)
	arrange(b,B)

	ret=''
	ret=(min(A[2],B[3])+min(B[2],A[3]))*'7'

	A[2],B[2]=max(0,A[2]-B[3]),max(0,B[2]-A[3])
	t=min(A[1]+B[1],A[1]+A[0],B[1]+B[0])
	A[0]=A[1]+A[0]-t
	B[0]=B[1]+B[0]-t
	ret=ret+(min(A[2],B[0])+min(B[2],A[0]))*'7'
	A[2],B[2]=max(0,A[2]-B[0]),max(0,B[2]-A[0])
	ret=ret+(min(t,A[2])+min(t,B[2]))*'7'
	k=min(max(0,t-A[2]),max(0,t-B[2]))

	A[2],B[2]=max(0,A[2]-t),max(0,B[2]-t)
	ret=ret+min(A[2],B[2])*'7'+k*'4'

	print(ret)
	return 


t=int(input())
for i in range(t):
	solve()



tests=int(input())
for t in range(tests):
	a=input()
	b=input()
	aSev=a.count('7')
	aLesS=a.count('5')+a.count('6')
	aFor=a.count('4')
	aLess=a.count('3')+a.count('2')+a.count('1')+a.count('0')
	bSev=b.count('7')
	bLesS=b.count('5')+b.count('6')
	bFor=b.count('4')
	bLess=b.count('3')+b.count('2')+b.count('1')+b.count('0')
	fin7=0
	fin4=0
	if aSev<=bLesS:
		fin7+=aSev
		bLesS-=aSev
		aSev=0
	else:
		fin7+=bLesS
		aSev-=bLesS
		bLesS=0
		if aSev<=bLess:
			fin7+=aSev
			bLess-=aSev
			aSev=0
		else:
			fin7+=bLess
			aSev-=bLess
			bLess=0
			if aSev<=bFor:
				fin7+=aSev
				bFor-=aSev
				aSev=0
			else:
				fin7+=bFor
				aSev-=bFor
				bFor=0
	if bSev<=aLesS:
		fin7+=bSev
		aLesS-=bSev
		bSev=0
	else:
		fin7+=aLesS
		bSev-=aLesS
		aLesS=0
		if bSev<=aLess:
			fin7+=bSev
			aLess-=bSev
			bSev=0
		else:
			fin7+=aLess
			bSev-=aLess
			aLess=0
			if bSev<=aFor:
				fin7+=bSev
				aFor-=bSev
				aSev=0
			else:
				fin7+=aFor
				bSev-=aFor
				aFor=0
	fin7+=min(aSev,bSev)
	if aFor<=bLess:
		fin4+=aFor
		bLess-=aFor
		aFor=0
	else:
		fin4+=bLess
		aFor-=bLess
		bLess=0
	if bFor<=aLess:
		fin4+=bFor
		aLess-=bFor
		bFor=0
	else:
		fin4+=aLess
		bFor-=aLess
		aLess=0
	fin4+=min(aFor,bFor)
	print('7'*fin7+'4'*fin4)
		


t=int(input())
for i in range(t):
    a=input()
    b=input()
    sa,sb,fa,fb,ac1,ac2,bc1,bc2=0,0,0,0,0,0,0,0
    for x in a:
        if x<'4': ac1+=1
        elif x=='4': fa+=1
        elif x<'7': ac2+=1
        elif x=='7': sa+=1
    for x in b:
        if x<'4': bc1+=1
        elif x=='4': fb+=1
        elif x<'7': bc2+=1
        elif x=='7': sb+=1

    final7,final4=0,0
    #print sa,fa,ac1,ac2
    #print sb,fb,bc1,bc2

    # Check for 7s in A
    if sa:
        x=sa if bc2>sa else bc2
        final7+=x
        sa-=x
        bc2-=x
        x=sa if bc1>sa else bc1
        final7+=x
        sa-=x
        bc1-=x
        if sa:
            x=sa if fb>sa else fb
            final7+=x
            sa-=x
            fb-=x
    if sb:
        x=sb if ac2>sb else ac2
        final7+=x
        sb-=x
        ac2-=x
        x=sb if ac1>sb else ac1
        final7+=x
        sb-=x
        ac1-=x
        if sb:
            x=sb if fa>sb else fa
            final7+=x
            sb-=x
            fa-=x
    if fa:
        x=fa if bc1>fa else bc1
        final4+=x
        fa-=x
        bc1-=x
    if fb:
        x=fb if ac1>fb else ac1
        final4+=x
        fb-=x
        ac1-=x
    final4+=min(fa,fb)
    final7+=min(sa,sb)
    print('7'*final7+'4'*final4)
    


import sys

def analyze(string):
	sevens = 0
	low = 0
	mid = 0
	high = 0
	fours = 0
	for c in string:
		if c > '7':
			high = high + 1
		elif c == '7':
			sevens = sevens +1
		elif c == '4' :
			fours = fours + 1
		elif c < '4':
			low = low +1 
		else:
			mid = mid + 1

	return (sevens,fours,high,mid,low)	

def solve(A,B):
	l = len(A)
	a = analyze(A)
	b = analyze(B)
	(a_s, a_f, a_h, a_m, a_l) = a
	(b_s, b_f, b_h, b_m, b_l) = b

	c_s = 0
	c_f = 0

	# Start by removing high values
	if a_h > b_h :
		# Remove high values
		l = l - (a_h)
		# Hide mid values under high values
		b_m = max(b_m - (a_h - b_h),0)
	elif b_h > a_h :
		# Remove high values
		l = l - (b_h)
		# Hide mid values under high values
		a_m = max(a_m - (b_h - a_h),0)
	else:	
		l = l - a_h

	c_s = a_s + b_s	

	l = l - c_s

	if l <= 0:
		c_s = c_s + l
		return (c_s,c_f)
	
	# Hide mid values under sevens
	a_m = max(a_m - b_s,0)
	b_m = max(b_m - a_s,0)
	
# Removing mid values	

	l = l - max(a_m,b_m)

	# Check how many fours can be arranged..

	c_f = a_f + b_f
	l = l - c_f

	if l <= 0:
		c_f = c_f + l

	return (c_s,c_f)
		
def show(s,f):
	print(s * '7' + f * '4')
	

f = sys.stdin

for test in range(int(f.readline())):
	A = f.readline().rstrip()
	B = f.readline().rstrip()
	(c_s,c_f) =  solve(A,B)
	show(c_s,c_f)


t=int(input())
for i in range(t):
    a=input()
    b=input()
    sa,sb,fa,fb,ac1,ac2,bc1,bc2=0,0,0,0,0,0,0,0
    for x in a:
        if x<'4': ac1+=1
        elif x=='4': fa+=1
        elif x<'7': ac2+=1
        elif x=='7': sa+=1
    for x in b:
        if x<'4': bc1+=1
        elif x=='4': fb+=1
        elif x<'7': bc2+=1
        elif x=='7': sb+=1

    final7,final4=0,0
    #print sa,fa,ac1,ac2
    #print sb,fb,bc1,bc2

    # Check for 7s in A
    if sa:
        x=sa if bc2>sa else bc2
        final7+=x
        sa-=x
        bc2-=x
        x=sa if bc1>sa else bc1
        final7+=x
        sa-=x
        bc1-=x
        if sa:
            x=sa if fb>sa else fb
            final7+=x
            sa-=x
            fb-=x
    if sb:
        x=sb if ac2>sb else ac2
        final7+=x
        sb-=x
        ac2-=x
        x=sb if ac1>sb else ac1
        final7+=x
        sb-=x
        ac1-=x
        if sb:
            x=sb if fa>sb else fa
            final7+=x
            sb-=x
            fa-=x
    if fa:
        x=fa if bc1>fa else bc1
        final4+=x
        fa-=x
        bc1-=x
    if fb:
        x=fb if ac1>fb else ac1
        final4+=x
        fb-=x
        ac1-=x
    final4+=min(fa,fb)
    final7+=min(sa,sb)
    print('7'*final7+'4'*final4)