What's In A Name?

No attempts yetTime limit1sMemory limit128 MB

Problem

The FBI is watching a hideout that a group of criminals uses as a communication center. By decrypting the e-mail leaving the site they can read every message and see the sender's user ID, but the criminals pick random strings of letters as IDs, so an ID on its own reveals nothing. Each criminal uses exactly one ID, and no two criminals share an ID.

The only extra information the FBI has is a log of who enters and leaves the hideout. A message can only be sent by someone who is physically inside at that moment, so whenever a message from a given ID is intercepted, the owner of that ID must be one of the people currently in the hideout. Combining the comings, goings, and intercepted messages is often enough to pin an ID down to a single name.

For each criminal, decide whether the log determines their user ID uniquely.

Input

The first line contains a single integer TT, the number of test cases. A blank line precedes each test case, and consecutive test cases are separated by a blank line.

Each test case begins with a line containing a single positive integer nn (1n201 \le n \le 20), the number of criminals using the hideout. The next line contains the nn user IDs separated by single spaces (this line may be longer than 80 characters).

The remaining lines are the log entries in chronological order. Each entry has the form type arg:

  • E arg — the criminal named arg entered the hideout.
  • L arg — the criminal named arg left the hideout.
  • M arg — a message was intercepted from user ID arg.

A line containing only the letter Q marks the end of the log. The hideout is empty at the start of the log. Not every user ID needs to appear in the log, but every criminal name is guaranteed to appear at least once. All names and user IDs consist of lowercase letters only and have length at most 20.

Output

For each test case, output nn lines, sorted alphabetically by criminal name. Each line has the form name:userid, where userid is that criminal's user ID if the log determines it uniquely, or ??? if it cannot be determined. Separate the output of consecutive test cases with a blank line.