Problem A
Grandpa Bernie
Over the years, Grandpa Bernie has traveled all over the world. He doesn’t travel that much anymore, but he loves to tell his grandchildren stories from all these trips. He’ll tell them the story from when he went to Israel for the first time, or when he went to Greece for the third time.
His memory works in a funny way. He can easily remember his
Input
The input consists of:
-
one line with one integer
( ), the number of trips Grandpa Bernie went on; -
lines each containing the name ( ) of a country and an integer ( ) representing a trip to country that Grandpa Bernie went on in year ; -
one line with one integer
( ), the number of queries; -
lines each containing the name of a country and an integer representing a query for the :th time Grandpa Bernie went to country .
Each country name only consists of letters from the English
alphabet. It is also guaranteed that, for each query asking for
the
Output
For each query for the
Sample Input 1 | Sample Output 1 |
---|---|
4 Iceland 2016 Sweden 2015 Iceland 1982 Norway 1999 3 Sweden 1 Iceland 1 Iceland 2 |
2015 1982 2016 |
Sample Input 2 | Sample Output 2 |
---|---|
4 Iceland 2014 Iceland 2015 Iceland 2015 Iceland 2016 4 Iceland 4 Iceland 3 Iceland 2 Iceland 1 |
2016 2015 2015 2014 |