Word Match

(1995 ACS Problem G)


A solution for this problem can be found here.

As a secret service agent, you monitor all computer email traffic, searching for keywords that suggest subversive activities. However, some subversive elements in society have started scrambling the letters in some words of their email messages in an attempt to evade detection.

You, undeterred by such transparent tricks, decide to write a program that searches sentences for suspicous words whose letters have been rearranged.

INPUT

The input contains pairs of lists and sentences. The list gives the words to search for in the following sentence. All letters in the input are in lower case. Words are at most 20 letters long and are seperated by a single space. Each line is at most 80 characters long. Each list fits on a single line and contains at most 20 words. Sentences may occupy more than one line, and are terminated by a full stop.

The end of input is denoted by a list containing only a #.

OUTPUT

For each pair of list and sentence, find the words from the list that appear in the sentence with their letters shuffled. Print these words in the order they appear in the list, separated by a single space. If no words from the list match the words in the sentence, just print a blank line.



SAMPLE INPUT

bomb
we twan ot ombb mericaa.
guns mines missiles
aameric ssell snug
dan iimsssle ot sit neeemis.
cat sat mat
cat sat tam mat.
#

SAMPLE OUTPUT

bomb
guns missiles
cat sat mat


This problem was Problem G in the 1995 ACS Australian Programming Competition.