no tags 


Don and his friends had some sort of code word to describe the girls who pass towards their class.

Anitha passed - killer told.. “Dude, 5 2 is going”

Chitra passed - Jumbo told.. “Dude, 6 4 is awesome”

Divya passed - Baabi told.. “Machi 1 6 is my dream girl”

Girls couldn’t understand those code words. To crack the code word, girls decide to record all the code words and the girls' name whenever they call.

The silencer in the class watched all these and got angry. He mugged up all the code words, went to teacher and complained about the naughty boys and naughty girls.

Teacher : Who is the girl with code word 1 6?

Silencer: Divya

Teacher: Who is the girl with code word  5 2?

Silencer: Anitha

Teacher: What is the code word for me??

Silencer: (puzzled)

Now you have to pretend that you are the Silencer to solve this problem. Record the code words and answer the questions the teacher asks you.(She may ask the same question any number of times)

Note: There can be any number of code words for a same girl. If there exist more than one girl for a same code word, then that code word belongs to the latest girl. 

Input Specification:

The first line contains an integer n, the number of figures. Then in each of the next n lines there will be 2 integers and a figure name.

After that there will be an integer t, the number of test cases. For each test case, there will be two integers representing the code word. Print the figure’s name corresponding to the code word.

Output Specification:

For each test case output the figure name.

Input Constraints:



-1000000<=code1, code2<=1000000

The figure’s name will not exceed 20 characters 

Sample Input:


5 2 Anitha

6 4 Yamuna

6 4 Chitra

1 6 Divya

-2 0 Teacher

7 4 Anitha


-2 0

6 4

Sample Output:



Hint: Use map

hide comments
jorvis: 2019-05-30 08:05:08

For all those trying to submit solution in Java, I know its a challenging one to overcome the Time Limit problem.
But keep on trying(in Java only), this problem is really a good one for doing optimization in Java Code.

lamia2658: 2018-08-10 06:49:10

hashing makes it easy

goutam_giri: 2018-05-17 12:46:17

For java i am getting TLE can any one share test cases ?

Last edit: 2018-05-17 12:46:37
watchfriends: 2017-10-06 10:05:02

It not getting submitted

sun_65: 2017-08-28 11:34:57

AC in one go :P

Added by:cegprakash
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: BF