Problem A
Candy Store
Candy runs, well, a candy store! It is very popular, she has a hard time keeping up with all the orders being placed. She implements a simple system. Each customer who enters the store will fill their order on a form and sign it with their initials.
Maybe she should have asked for their full name instead, since this can sometimes lead to ambiguities about who placed the order. Actually, maybe she should not have let the customers write their own initials because sometimes she might misread them.
At times, Candy needs to consult with the customers about their order. She calls the initials written on the order form. Each time Candy calls out some initials, help her by informing her who the initials corresponds to, or if there are multiple names the initials correspond to, or if nobody has those initials.
Input
The first line of input will contain two integers $N$ ($1\le N\le 100$) and $Q$ ($1\le Q\le 100$), denoting the number of customers in the store who have submitted an order and number of initials to query, respectively. The next $N$ lines each contain one name, which is two words separated by a single space. Each of the two words starts with an uppercase letter and is followed by lowercase letters. The length of each word is between $2$ and $10$ characters. No two of the $N$ customers will have the exact same name, though some customers may share the same first name or the same last name.
The next $Q$ lines each contains exactly two uppercase letters describing the initials of a customer Candy wants to talk to.
Output
For each of the $Q$ queries, output one of the following:
-
If there is exactly one name that matches the initials, output the name.
-
If there is no name that matches, output nobody
-
If there is more than one name that matches, output ambiguous
Sample Input 1 | Sample Output 1 |
---|---|
4 3 John Doe Jane Doe Jimmy Jimmy Door Jone JJ JD NW |
Jimmy Jimmy ambiguous nobody |