Candy Store

시간 제한1초메모리 제한2048 MB

요약
각 고객 이름의 두 머리글자를 이름에 대응시킨 뒤, 질의마다 이름, nobody, ambiguous 중 하나를 출력한다.
난이도

쉬움10점 중 2점

유형
해시맵, 문자열
정답자
아직 제출이 없습니다

문제

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.

입력

The first line of input will contain two integers NN (1≤N≤1001≤N≤100) and QQ (1≤Q≤1001≤Q≤100), denoting the number of customers in the store who have submitted an order and number of initials to query, respectively. The next NN 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 22 and 1010 characters. No two of the NN customers will have the exact same name, though some customers may share the same first name or the same last name.

The next QQ lines each contains exactly two uppercase letters describing the initials of a customer Candy wants to talk to.

출력

For each of the QQ 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

예제1

  1. 예제 1

    입력
    4 3
    John Doe
    Jane Doe
    Jimmy Jimmy
    Door Jone
    JJ
    JD
    NW
    
    예상 출력
    Jimmy Jimmy
    ambiguous
    nobody