Modern cellular phones have a small chip, called a SIM card, that allows the phone to interface with the carrier's network. SIM cards also have a small amount of memory onboard where the user can store data, such as names, phone numbers, and e-mail addresses. A common problem with SIM card memory is that it cannot group several numbers under the same name, as most cell phones can. This poses a problem when the user wishes to switch phones. The easiest way to transfer contacts is to copy them to the SIM card from the old phone, and then copy them back from the SIM card to the new phone. However, if the user has multiple phone numbers and/or e- mail addresses for a given name, the contact information will be broken up, with multiple entries of the same name, each associated with a different phone number or e-mail address.
Obviously, the user of the new phone would like for his or her contact data to be organized, with each contact's name listed only once, and the various phone numbers and e-mail addresses for that contact organized under that single entry. You are to write a program to help with this.
Given the contact data from a SIM card, consisting of pairs of names and email addresses or names and phone numbers, generate organized input data for the new cell phone. The new cell phone has a strict data format that must be followed precisely (the format is described in The Output section below).
There will be multiple contact lists (test cases) to process. The first line of each contact list contains a single integer, n(1≤n≤100), indicating the number of contact data entries on the SIM card. On each of the next nn lines will be a name, followed by either a phone number or an e-mail address. Names consist of exactly two strings of upper- and lower-case alphabetic characters (the first name followed by the last name). Each first (last) name is at least one character and at most 20 characters. There will be exactly one space between the first and last names in input, and one space between the last name and the phone number or e-mail address. A phone number will consist of exactly 10 digits (no hyphens). An e-mail address will consist of a string of letters and/or numbers separated by exactly one at ('@') sign, and at least one dot ('.'). No input line will exceed 80 characters. There will be no leading or trailing whitespace on any line.
End of input is indicated by a value of 0 for n. This case should not be processed.
For each data set, print the heading "Contact list #d:" where dd is the set number in the input (starting with 1). Then, for each unique contact (by name) in the set, output a contact entry. Note that case is significant, so "John DOE" is a different contact from "John Doe". Contact entries must be output in the following format:
<Phone Number 1>
<Phone Number 2>
<Phone Number p>
<E-Mail Address 1>
<E-Mail Address 2>
<E-Mail Address q>
Phone numbers should be printed in the format "(123)456-7890". E-mail addresses should be printed exactly as input. Contact entries should be output in ascending ASCII order by last name, then first name. Within each contact, phone numbers should be output in numerical order, and e-mail addresses should be output in ascending ASCII order. There must be no leading or trailing spaces in the output. (Note that the built-in string comparison functions do compare strings in ASCII order.)
Leave a blank line after the output for each data set. Follow the format illustrated in Sample Output.
6 John Doe 4071234567 Bill Smith email@example.com Bill Smith 1231231234 John Doe John.Doe@my.house.net John Doe John.Doe@work.com Bill Smith 1234567890 2 Bone Head 1231231234 Air Head firstname.lastname@example.org 0
Contact list #1: John Doe Phone: (407)123-4567 E-Mail: John.Doe@my.house.net John.Doe@work.com ### Bill Smith Phone: (123)123-1234 (123)456-7890 E-Mail: email@example.com ### Contact list #2: Air Head Phone: E-Mail: firstname.lastname@example.org ### Bone Head Phone: (123)123-1234 E-Mail: ###