<commit_before>"""
    https://www.hackerrank.com/challenges/morgan-and-a-string/problem
2
JACK
DANIEL
ABACABA
ABACABA
-
DAJACKNIEL
AABABACABACABA



"""


def morganAndString(a, b):
    result = []
    i = 0
    j = 0
    while i < len(a) and j < len(b):
        if a[i] < b[j]:
            result.append(a[i])
            i += 1
        elif a[i] > b[j]:
            result.append(b[j])
            j += 1
        else:
            result.append(a[i])
            i += 1
    while i < len(a):
        result.append(a[i])
        i += 1
    while j < len(b):
        result.append(b[j])
        j += 1
    print(''.join(result))


t = int(input())
for t_itr in range(t):
    a = input()
    b = input()
    morganAndString(a, b)<commit_msg>logic update with new found edge cases<commit_after>"""
    https://www.hackerrank.com/challenges/morgan-and-a-string/problem
2
JACK
DANIEL
ABACABA
ABACABA
-
DAJACKNIEL
AABABACABACABA

DAJACKNIEL
AABABACABACABA

Incase of an equal string make sure you check for lexicographically minimal string.
For time saving, when we check for lexicographically least string return merged peace as well.
"""


def lexicographicalorder(a, b, i, j):
    result = []


def morganAndString(a, b):
    result = []
    i = 0
    j = 0
    while i < len(a) and j < len(b):
        if a[i] < b[j]:
            result.append(a[i])
            i += 1
        elif a[i] > b[j]:
            result.append(b[j])
            j += 1
        else:
            result.append(a[i])
            i += 1
    while i < len(a):
        result.append(a[i])
        i += 1
    while j < len(b):
        result.append(b[j])
        j += 1
    print(''.join(result))


t = int(input())
for t_itr in range(t):
    a = input()
    b = input()
    morganAndString(a, b)

lexicographicalorder("ZJWDEGFNRMTIYSXLVFDJVMTLPSX","ZJPVFQCGSRYJAFEJETMCVFSLIQM",0,0)
{'fraction_non_alphanumeric': 0.13754045307443366, 'fraction_numerical': 0.009708737864077669, 'mean_word_length': 2.031045751633987, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2394556', 'n_tokens_mistral': 742, 'n_tokens_neox': 700, 'n_words': 170}