words_definitions = input()
dictionary = {}
words_definitions_split = words_definitions.split(" | ")
for word_definition in words_definitions_split:
word_definition_split = word_definition.split(": ")
word = word_definition_split[0]
definition = word_definition_split[1]
if word not in dictionary:
dictionary[word] = []
dictionary[word].append(definition)
else:
dictionary[word].append(definition)
only_word = input()
only_word_split = only_word.split(" | ")
command = input()
for el in only_word_split: # изкарвами думите, които се подават
if command == "Test":
if el in dictionary:
print(f"{el}:")
for definition in (dictionary[el]):
print(f" -{definition}")
else:
for word in dictionary.keys():
print(word, end=" ")
exit()