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.
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.
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.
## 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.
[samples]
**Definitions**
Let $ t \in \mathbb{Z} $ be the number of test cases.
For each test case:
- Let $ N \in \mathbb{Z} $ be the number of teams, numbered $ 1 $ to $ N $.
- Let $ Q \in \mathbb{Z} $ be the number of events.
- Let $ E = \{(x_i, p_i) \mid i \in \{1, \dots, Q\}\} $ be the sequence of events, where $ x_i \in \{1, \dots, N\} $ is the team ID and $ p_i \in \mathbb{Z} \setminus \{0\} $ is the point change.
- Let $ S_i(j) \in \mathbb{Z} $ denote the score of team $ j $ after the $ i $-th event, with $ S_0(j) = 0 $ for all $ j $.
- Define the winner at event $ i $ as the team $ w_i = \arg\max_{j \in \{1,\dots,N\}} (S_i(j), -j) $ under lexicographic order (max score, then min ID in case of tie).
**Constraints**
1. $ 1 \le t \le 1000 $
2. For each test case:
- $ 1 \le N, Q \le 10^5 $
- $ 1 \le x_i \le N $
- $ -100 \le p_i \le 100 $, $ p_i \ne 0 $
3. Events are processed in chronological order.
**Objective**
Find the smallest $ i \in \{0, 1, \dots, Q\} $ such that for all $ j \ge i $, $ w_j = w_i $.
If no such $ i > 0 $ exists (i.e., winner never changes from the start), output $ 0 $.
Otherwise, output the smallest such $ i \in \{1, \dots, Q\} $.