By providing one or more MX records (lines of text in a particular file), a system manager can arrange for DNS to route mail bound for one machine to another instead. Rerouting is appropriate in many cases, but one frequent use is to create addresses for fictitious machines with meaningful names. For example, it might be nice to allow mail to be addressed to info.stateu.edu, but not have a specific machine named info on the stateu campus. The mail could be redirected to bigone.stateu.edu by using an appropriate MX record. In this problem we'll deal with processing a simplified form of MX records.
An MX record has three fields, or sequences of non-blank characters. These fields are separated by one or more blanks. The first field, if present, always begins in the first column on a line. If the first field is not present, then it is assumed to be the same as the first field from the preceding line (or the one assumed for that line if it didn't have one). The first and third fields are symbolic machine names, and will contain no more than 36 characters. The second field is a non-negative integer specifying a preference. Let's look at an example.
info.stateu.edu 0 bigone.stateu.edu 10 tiny.stateu.eduThe first line says that all mail destined for info.stateu.edu should be delivered to bigone.stateu.edu. The preference in this MX record is 0, versus 10 for the second MX record. If bigone.stateu.edu is down, then mail for info would instead be redirected to tiny. Smaller numbers indicate higher preference, and MX records need not be given in order of increasing preference.
Wildcard MX records allow redirection of mail to many machines with a single MX record. For example,
*.citycc.midville.edu 0 tiny.stateu.eduwould redirect mail to any machine whose name has the symbolic suffix .citycc.midville.edu to the machine tiny on the stateu campus. For simplicity, we will assume that the asterisk (*) representing a wildcard record will appear only in the first part of a wildcarded symbolic name, and that no more than three periods will occur in any symbolic name.
Sample Input
5 service.stateu.edu 10 tiny.stateu.edu info.stateu.edu 0 bigone.stateu.edu 10 tiny.stateu.edu service.stateu.edu 5 bigone.stateu.edu *.smallu.edu 10 service.stateu.edu A alpha.cs.smallu.edu A info.stateu.edu D bigone.stateu.edu A info.stateu.edu A nowhere.com X
alpha.cs.smallu.edu => service.stateu.edu info.stateu.edu => bigone.stateu.edu info.stateu.edu => tiny.stateu.edu nowhere.com =>