Index 

The index found near the end of a textbook is an essential feature, and is possibly referenced more frequently than the table of contents. Of course only selected terms appear in the index. In this problem you will create a small index.


A normal index must deal with upper- and lower-case terms, unusual punctuation, and index terms with multiple words. In this problem index terms will consist only of single words consisting of sequences of at most 10 letters and digits, with all letters converted to upper case in the index. Punctuation preceding or following an index term will be ignored. No terms will have imbedded punctuation. An index will frequently have lists of references that exceed the length of a line, but in this problem that problem will be ignored. Each index term and the list of lines on which it appears appear as a single separate line in the output.


A normal index identifies the page on which a term appears. To keep the size of the input for this problem manageable, your index will identify the line on which a term appears. Lines in the text to be indexed are numbered sequentially, starting with 1.

Input 

The input for this problem will consist of multiple test cases. Each test case has two components: the list of index terms, and the text to be indexed. The list of index terms will have one term per line starting in column one with the end of line immediately following the last character in the term. The list of index terms will be unordered, and the individual terms may include both upper- and lower-case characters (which are, of course, to be converted to upper case only). An empty line will follow the last index term. The text to be indexed consists of an arbitrary number of lines followed by an empty line. An extra empty line will follow the last test case.

Output 

For each test case, the output is to begin with identification of the case (they are numbered sequentially, starting with 1). The index lines follow this, including one line for each index term appearing in the text; index terms that do not appear in the text do not appear in the output. Each line contains the index term, a space, and a comma-separated list of the line numbers on which the index term appears. If an index term appears on several consecutive lines, then the index specifies the range of lines on which it appears, indicated by the first and last line number in the range, separated by a hyphen. The example input and output following illustrate all of the cases you will need to consider.

Sample Input 

empty
character
of
for
it

An empty line has no characters in it at all (except for
the end of line character). No word will have more than
ten characters in it. The end of the cases will be followed
by another empty line. It follows the empty line ending the
text of the last case.

Repeat
A
line

A repeat of a word on a line does not result in a repeat of the
line number in the index.

Sample Output 

Case 1
CHARACTER 2
EMPTY 1, 4
FOR 1
IT 1, 3-4
OF 2-3, 5

Case 2
A 1
LINE 1-2
REPEAT 1



Miguel Revilla
2000-08-14