We know the normal alphabetical order of the English alphabet, so we can sort words or other strings. For instance these words are sorted:
ANTLER
ANY
COW
HILL
HOW
HOWEVER
WHATEVER
ZONE
The standard rules for sorting strings are used:
The Gorellians, at the far end of our galaxy, found various samples of English text in our electronic transmissions, but they did not find the order of our alphabet. They are a very organized and orderly species, and they want a way of ordering words even in the strange symbols of English, so they have to settle on an order of their own. Unfortunately they cannot agree, and every Gorellian year they argue and settle on a new order.
Suppose they agree on the alphabetical order
UVWXYZNOPQRSTHIJKLMABCDEFG
Then the words above are sorted as
WHATEVER
ZONE
HOW
HOWEVER
HILL
ANY
ANTLER
COW
The first letters of the words are in their alphabetical order. Where words have the same prefix, the first differing letter sets the order, so ANY comes before ANTLER because Y is before T in their choice of alphabet. HOWEVER still comes after HOW, since HOW is a prefix of HOWEVER.
Handling a different alphabetical order every year by hand (or by tentacle) is tedious. Write a program that sorts the English letters in a specified sequence.
The input contains one or more datasets. Each dataset starts with a line containing an integer n and a string s, where s is a permutation of the 26 uppercase English letters and is the Gorellians' alphabet for the coming year. The next n lines each contain one non-empty string of letters (1≤n≤20). The length of each string is no more than 30. Following the last dataset is a line containing only 0.
For each dataset, first print a line with year, one space, and the number of the dataset, counting from 1. Then print the n input strings on n lines, sorted by the alphabet order given in s, one per line.