403283: GYM101102 C Bored Judge

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Bored Judgetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Judge Bahosain was bored at ACM AmrahCPC 2016 as the winner of the contest had the first rank from the second hour until the end of the contest.

Bahosain is studying the results of the past contests to improve the problem sets he writes and make sure this won’t happen again.

Bahosain will provide you with the log file of each contest, your task is to find the first moment after which the winner of the contest doesn’t change.

The winner of the contest is the team with the highest points. If there’s more than one team with the same points, then the winner is the team with smallest team ID number.

Input

The first line of input contains a single integer T, the number of test cases.

The first line of each test case contains two space-separated integers N and Q (1 ≤ N, Q ≤ 105), the number of teams and the number of events in the log file. Teams are numbered from 1 to N.

Each of the following Q lines represents an event in the form: X P, which means team number X (1 ≤ X ≤ N) got P ( - 100 ≤ P ≤ 100, P ≠ 0) points. Note that P can be negative, in this case it represents an unsuccessful hacking attempt.

Log events are given in the chronological order.

Initially, the score of each team is zero.

Output

For each test case, if the winner of the contest never changes during the contest, print 0. Otherwise, print the number of the first event after which the winner of the contest didn’t change. Log events are numbered from 1 to Q in the given order.

ExampleInput
1
5 7
4 5
3 4
2 1
1 10
4 8
3 -5
4 2
Output
5

加入题单

算法标签: