import re
def process_main3():
    row1 = raw_input()
    datas = {}
    entity_str_list = row1.split(";")
    for entity_str in entity_str_list:
        entity_name, entity_values = entity_str.split("_")
        entity_value_list = entity_values.split("|")
        for entity_value in entity_value_list:
            if datas.has_key(entity_value):
                datas[entity_value].append(entity_name)
            else:
                datas[entity_value] = [entity_name]
    entity_list = sorted(datas.keys(), reverse=True)
    row2 = raw_input()
    words = row2
    result = {}
    tmp_words = words
    temp_entity = ""
    count = 1
    for entity_value in entity_list:
        if entity_value in tmp_words:
            location = re.search(entity_value, words)
            local_tuple = location.span()
            if temp_entity == "":
                temp_entity = entity_value
                temp_tuple = local_tuple
            else:
                result[temp_entity] = datas[temp_entity]
                tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
                count += 1
                temp_entity = entity_value
                temp_tuple = local_tuple
        else:
            if temp_entity != "":
                result[temp_entity] = datas[temp_entity]
                tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
                count += 1
                temp_entity = ""
    if temp_entity != "":
        result[temp_entity] = datas[temp_entity]
        tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
    final_list = sorted(result.keys(), reverse=True)
    for index in xrange(len(final_list)):
        st = ",".join(result[final_list[index]])
        new_str = " " + final_list[index] + "/" + st + " "
        tmp_words = tmp_words.replace("|&{}&|".format(index + 1), new_str)
    print " ".join(tmp_words.split())

if __name__ == '__main__':
    # main_process()
    process_main3()
# singer_周杰|周杰伦|刘德华|王力宏;song_冰雨|北京欢迎你|七里香;actor_周杰伦|孙俪
# 请播放周杰伦的七里香给周杰伦周杰孙俪听周杰王力宏