#K35252. Busiest Intersection

    ID: 25490 Type: Default 1000ms 256MiB

Busiest Intersection

Busiest Intersection

You are given traffic data from several intersections. For each test case, you need to determine the intersection with the highest total vehicle count. In the event of a tie, choose the intersection with the lexicographically smallest identifier.

Formally, for each test case with N intersections where each intersection is represented by a pair \( (s, c) \) (with \( s \) being the intersection identifier and \( c \) the vehicle count), find the intersection \( s^* \) such that

[ s^* = \min_{s \in S} { s : c = \max_{(s,c) \in S} c } ]

where \( S \) is the set of intersections in the test case. Output the answer for each test case on a new line.

inputFormat

The first line of input contains an integer \( T \) representing the number of test cases. For each test case:

  • The first line contains an integer \( N \) representing the number of intersections.
  • The next \( N \) lines each contain an intersection identifier (a string without spaces) and an integer representing the vehicle count, separated by a space.

Input is read from standard input.

outputFormat

For each test case, output a single line containing the identifier of the busiest intersection. Output is written to standard output.

## sample
2
3
A1 1500
B2 2000
C3 1500
4
X1 1000
Y2 3000
Z3 3000
W4 2500
B2

Y2

</p>