User Names

No attempts yetTime limit3sMemory limit256 MB

Problem

A university's computer system assigns each person a user name using the following rules.

  1. A user name is at most MAXLEN characters long. The value of MAXLEN is given in the input for each test case.
  2. The first character of the user name is the first letter of the person's first name, converted to lower case. Apostrophes and hyphens are ignored here and in Rule 3.
  3. Append as many letters of the person's last name as possible (converted to lower case) without making the user name longer than MAXLEN characters. Start from the first letter of the last name and append the letters in the order they appear.
  4. If the user name produced by Rules 1–3 already exists in the database, resolve the collision by appending the serial numbers 19, in that order, to the user name from Rule 3, as long as the result does not exceed MAXLEN characters. If appending a single digit would exceed MAXLEN, drop the last letter before appending the serial number.
  5. If the user name produced by Rules 1–4 already exists in the database, resolve the collision by appending the serial numbers 1099, in that order, to the user name from Rule 3, as long as the result does not exceed MAXLEN characters. If appending two digits would exceed MAXLEN, drop the last letter, or the last two letters, as needed, before appending the serial number.
  6. You may assume that these rules are always enough to avoid collisions.

Input

The input contains several test cases. The first line of each test case contains two positive integers: the number of names and the value of MAXLEN ($5 \le \text{MAXLEN} \le 80$). The list of names follows.

Each name is at most 80 characters long. It begins with the first name, is followed by middle names (if any), and ends with the last name; a single space separates consecutive parts. A name may contain upper- and lower-case letters, hyphens, and apostrophes. The last name has at least two letters; every other part has at least one letter (some parts may be just initials). Each test case has at most 200 names.

The last test case is followed by a line containing two zeros (the number of names and MAXLEN), which is not processed.

Output

For each test case, first print a line with the case number in the form Case k (where k starts at 1). Then print the generated user names, one per line, in the same order as the corresponding names in the input.