Sort Me

No attempts yetTime limit1sMemory limit128 MB

Problem

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:

  1. The first letters are in alphabetical order.
  2. Among strings with the same prefix, like the prefix AN in ANTLER and ANY, the first character that differs sets the order, T or Y here.
  3. One whole string may be a prefix of another string, like HOW and HOWEVER. In this case the shorter one comes first and the longer one comes after it.

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.

Input

The input contains one or more datasets. Each dataset starts with a line containing an integer nn and a string ss, where ss is a permutation of the 26 uppercase English letters and is the Gorellians' alphabet for the coming year. The next nn lines each contain one non-empty string of letters (1n201 \le n \le 20). The length of each string is no more than 30. Following the last dataset is a line containing only 0.

Output

For each dataset, first print a line with year, one space, and the number of the dataset, counting from 1. Then print the nn input strings on nn lines, sorted by the alphabet order given in ss, one per line.