Inspector

No attempts yetTime limit5sMemory limit128 MB

Problem

Inspector Byteasar is investigating a crime that happened at a software company, and he is trying to reconstruct the chain of events. The programmers, unfortunately, are quite absent-minded. The most useful things he can get from them are statements such as: "When I glanced at the clock at 14:42, there were five other programmers besides me logged in on the server."

Each programmer came to the office once during that day, stayed for one continuous stretch of time without ever stepping out, and then left for good, never returning the same day.

Baffled by the statements, Byteasar is not even sure they can all be trusted. Before anything else he wants to know whether it is at all possible that every statement is true at the same time. Help him find out.

Input

The first line contains an integer zz (1z501 \le z \le 50), the number of test cases. The test cases follow one after another.

The first line of each test case contains two integers nn and mm (1n,m1000001 \le n, m \le 100\,000): the number of programmers working in the office and the number of statements recorded by Byteasar. The programmers are numbered from 11 to nn.

Each of the next mm lines describes one statement with three integers tt, jj and ii (1tm1 \le t \le m, 1jn1 \le j \le n, 0in0 \le i \le n): programmer jj claims that at moment tt he was in the office and that, apart from himself, exactly ii other programmers were there. Every programmer's arrival and departure happen at moments different from all the moments mentioned in the statements (that is, strictly before, after, or between them).

Output

For each test case print a single line with one positive integer kk (1km1 \le k \le m): the largest number of leading statements that can all be true at once. In other words, the first kk statements can hold simultaneously, but the first k+1k+1 cannot. If all mm statements can be true together, print mm.

Notes

In the first example, the first four statements can hold at the same time, but adding the fifth one makes them contradictory: programmers 11 and 22 would then both have to be present from moment 11 through moment 44, so at moment 22 there would be at least three programmers in the office (numbers 11, 22 and 33). That contradicts programmer 33, who says only one other programmer was with him at moment 22. Hence the answer is 44.

In the second example all three statements are mutually consistent, so the answer is 33.