# -*- coding: utf-8 -*-
"""
Created on Sun Feb  2 14:38:13 2020

@author: mahika banerjee

ACSL Contest #2

"""
def del_dc(wrd): 
    nw_str = ''
    las_ltr = ''
    for i in wrd:
        if i != las_ltr:
            nw_str += i
            las_ltr = i
    return nw_str

def del_vwl(wrd):
    nw_str = wrd[0]
    vwl = ["A", "E", "I", "O", "U"]
    for i in wrd[1:]:
        if i not in vwl:
            nw_str += i
    return nw_str

def del_lp(wd1, wd2):
    min_len = min(len(wd1), len(wd2))
    nw_wd1 = ''
    nw_wd2 = ''
    for i in range(min_len):
        if wd1[i] != wd2[i]:
            nw_wd1 += wd1[i]
            nw_wd2 += wd2[i]
    if len(wd1) > len(wd2):
        nw_wd1 += wd1[min_len:]
    if len(wd2) > len(wd1):
        nw_wd2 += wd2[min_len:]
    return nw_wd1, nw_wd2

while True:
    # Debug flag to display results after each step, 1: Display, 0: Hide
    dbg_flg = 0
    # Get input
    inp_str = input('Enter 2 strings with all capital letters [type "0" to exit]: ')
    # Check input whether to exit
    if inp_str == '0':
        print('Thank you!')
        break
    # Convert to Upper case to avoid any input issue
    inp_str = inp_str.upper()
    # Remove double consonant
    inp_str = del_dc(inp_str)
    if dbg_flg == 1:
        print('1-Double Cons: ', inp_str)
    # Split the input into 2 variables
    inp_lst = inp_str.split()
    # Remove vowels except the 1st
    wrd1 = del_vwl(inp_lst[0])
    wrd2 = del_vwl(inp_lst[1])
    if dbg_flg == 1:
        print('2-Vowl: ',wrd1, " ", wrd2)
    # Remove like position letters - for left to right
    wrd1, wrd2 = del_lp(wrd1, wrd2)
    if dbg_flg == 1:
        print('3-Like Posn (L-R): ', wrd1, ' ', wrd2)
    # Reverse the strings
    wrd1 = wrd1[::-1]
    wrd2 = wrd2[::-1]
    # Remove like position letters - for right to left
    wrd1, wrd2 = del_lp(wrd1, wrd2)
    # Reverse the strings back to normal
    wrd1 = wrd1[::-1]
    wrd2 = wrd2[::-1]
    if dbg_flg == 1:
        print('4-Like Posn (R-L): ', wrd1, ' ', wrd2)
    # Display the result
    print("The output:")
    if len(wrd1) == len(wrd2):
        wrd_lst = [wrd1, wrd2]
        wrd_lst.sort()
        print(wrd_lst[0])
    else:
        if len(wrd1) > len(wrd2):
            print(wrd2)
        else:
            print(wrd1)