P13387 [CodeChef] twstr
普及
题目描述

Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries are as follows:
She gives you the first few characters of a recipe; you have to print the complete recipe with the highest priority.
Note:
Every recipe has a unique priority

Input

First line contains an integer N - the number of recipes.
Followed by N strings Si along with an integer each Vi.
Si stands for the recipe and Vi for the priority.
It is followed by an integer Q - the number of queries.
Followed by Q strings Qi.
Each string Si, Qi contain only lowercase Latin alphabets ('a' - 'z') and '-'.

Output
Q – lines, each contain the answer for each of the query.
If for a query no recipe matches print "NO". (Without quotes)
Constraints:
0 <= N <= 1000

0 <= Q <= 1000

-10^9 <= Vi <= 10^9

1 <= |Si| <= 1000 (length of Si)

1 <= |Qi| <= 1000 (length of Qi)

Example

Input:
4
flour-with-eggs 100
chicken-ham -10
flour-without-eggs 200
fish-with-pepper 1100
6
f
flour-with
flour-with-
c
fl
chik

Output:
fish-with-pepper
flour-without-eggs
flour-with-eggs
chicken-ham
flour-without-eggs
NO

输入格式

见题面

输出格式

见题面

样例输入
4 flour-with-eggs 100 chicken-ham -10 flour-without-eggs 200 fish-with-pepper 1100 6 f flour-with flour-with- c fl chik
样例输出
fish-with-pepper flour-without-eggs flour-with-eggs chicken-ham flour-without-eggs NO