import re
import operator

def allindices(string, sub, offset=0):
    listindex = []
    i = string.find(sub, offset)
    while i >= 0:
        listindex.append(i)
        i = string.find(sub, i + 1)
    return listindex

def reaches_end(s1,s2,pos):
    """
    Returns True if s2 overlaps s1 on the right, starting at position pos in
    s1
    """
    #print s1[pos:]
    t = len(s1) -pos
    #print s2[:t]
    return s1[pos:] == s2[:t]

def overlap(s1,s2):
    """
    Returns lenght of max overlap if we were to stitch s2 to the right of s1
    """
    #loop over s2 from left to right and check for overlap
#    print 'OVERLAP',s1,s2
    for i in range(len(s2),0,-1):
        idxs = allindices(s1,s2[:i])
        if len(idxs) == 0:
            continue
        mx = max(idxs)
        if reaches_end(s1,s2,mx):
            return i
    return 0

def combine(s1,s2,pos):
    """
    Stitches s2 to the right of s1 at position pos
    """
    return s1[:-pos]+s2        

def split_input(st):
    result = []
    for c in st.split(';'):
        result.append(r'%s'%c)
    return result
def max_item(h):
    item = max(h.iteritems(), key=operator.itemgetter(1))
    return item

def create_dict(lines):
    """
    Given lines of string create a dictionary that maps from (s1,s2) --> int
    for each pair of strings in lines
    """
    d = {}
    maxsofar = {} # stores the max match so far for a word
    for s1 in lines:
        maxoverlap = 0
        match = ()
        for s2 in lines:
            if s1 == s2:
                continue
            ov = overlap(s1,s2)
            if ov > maxoverlap:
                maxoverlap = ov
                match = (s1,s2)
            #need smarter checking
        if maxoverlap > 0:
            d[match] = maxoverlap
    return d

def solve(strinput):
    #split input to get separate strings
    lines = split_input(strinput)
    d = create_dict(lines)
    while len(lines) > 1:
        #print '=================='
        #print 'DICT',d
        try:
            (words,value) = max_item(d)
            #print "words",words
            oldlen = len(lines)
            new_word = combine(words[0],words[1],value)
            #print "NEW",new_word
            #remove words that are substrings of the new word
            to_rm = []
            for elm in lines:
                if elm in new_word:
                    to_rm.append(elm)
            for e in to_rm:
                lines.remove(e)
            #update the dictionary by inserting the best match for the new word
            maxover = 0
            best_match = ()
            for elm in lines:
                lap = overlap(elm, new_word)
                if lap > maxover:
                    maxover = lap
                    best_match = (elm,new_word)
            if maxover > 0:
                d[best_match] = maxover
                #print 'BEST',best_match
            #remove the previous match from the dictionary
            del d[(words)]
            #remove elems in dict that contain words[0] or words[1]
            elms_delete = []
            for k in d:
                if words[0] == k[0] or words[1] == k[1]:
                    elms_delete.append(k)
            for e in elms_delete:
                del d[e]
            lines.append(new_word)
        except:
            raise Exception("dictionary empty")
    return lines[0]


import sys
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
   test = test.strip()
   test = r'%s'%test
   print solve(test)
test_cases.close()
