You are asked to find a good perfect matching for a group of equal numbers of male and female. To make the situation more realistic, each possible couple has a satisfaction rating representing how much they like each other.
Given the description of the set of possible couples with the corresponding rating, you are to find a perfect matching (i.e., every one is matched) such that the smallest rating of the couples made is maximized among all possible matchings. By doing so you can gurantee the resultant matching has certain kind of satisfaction.
The first integer in the input indicating the number of test sets.
For each test set, the first line has two integers n and m, where 0 < n ≤ 100, 0 < m ≤ 10000, n represents the number of males (and hence there are also n females) and m represents the number of possible couples.
Then m lines follow, each line has the form "a b r", 1 ≤ a, b ≤ n and 0 ≤ r ≤ 10000, which means that "male a" with "female b" is a possible couple with rating r.
For each test case, output a single line of the maximized smallest rating among all possible matchings.
2 4 13 1 1 3916 1 3 588 1 4 3925 2 2 9177 2 3 1353 3 1 3923 3 2 274 3 3 6182 3 4 3795 4 1 3777 4 2 219 4 3 682 4 4 4461 4 6 1 3 29 1 4 5349 2 1 171 2 3 1709 3 2 163 4 1 7287
3916 163