TnP Secretary Arusha is being assigned a job by the Training and Placement department to solve the following queries for the data to be submitted for the annual review report in different banks. Being a fitness enthusiast, she is too busy preparing for a marathon! Can you help her? The students will be judged on the basis of marks of three courses Data structures, graph theory and operating system.
INPUT:-
You will be given an integer T. which will denote the number of testcases. For each testcase, An integer n is given determining the strength of the batch. Next n lines consist of the details of the student which will be space separated. The details of the students will be Roll-id, Name , marks in data structures, marks in graph theory, marks in operating system. The next line consist of an integer q . The next q lines consist of queries. Each query consist of two integers a and b. a represents the list no. and b represents the rank. if a equals 1, return the name of the student whose rank equals b in the grand student list . if a equals 2, return the number of students same marks in data structure as that of the person whose rank equals b in the data structure marks list. if a equals 3, return the name of the student in whose rank equals b the graph theory marks list. if a equals 4, return the name of the student in whose rank equals b the operating system marks list.
The ranking is done in the following order in decreasing order of priority:- sum in all the subjects, data structure , graph theory, operating system, roll-id. Kindly note that next parameter will only be considered as a tie-breaker. i.e the data structrure marks of a pair of students will be compared iff they have a common sum score. and this rule is applicable for other parameters too.
The ranking of the subject list is done on the basis of individual marks scored in that particular subject . In case of a tie , the person with better rank in grand list will be given a better rank in the subject list too.
OUTPUT:- output the roll-id space in a single line for each query.
CONSTRAINTS:-
1<=t<=5
1<=n<=1000000
1<=length(roll_id)<=100
1<=ds_marks<=100
1<=gt_marks<=100
1<=os_marks<=100
1<=q<=100
1<=a<=4
1<=b<=n
No editorial available for this problem.