#C3321. Most Popular Product

    ID: 46736 Type: Default 1000ms 256MiB

Most Popular Product

You are given Q test cases. In each test case, there are N unique products and M purchase records. Each purchase record consists of two integers representing the user ID and the product ID. A user may purchase a product multiple times, but for the purpose of this problem, only unique purchases by different users count.

Your task is to determine the most popular product for each test case. The popularity of a product is measured by the number of unique users who made a purchase of that product. In case of ties, choose the product with the smallest ID.

Input Format: The input is given via standard input. The first line contains an integer Q, the number of test cases. Each test case begins with a line containing two space-separated integers N and M. This is followed by M lines, each containing two space-separated integers U (user ID) and P (product ID).

Output Format: For each test case, output a single line to standard output containing the ID of the most popular product.

The decision rule can be mathematically summarized as:

$$\text{For each product } p \text{, let } c(p) = \#\{\text{unique users buying } p\}.\\ \text{Answer} = \min \{ p \mid c(p) = \max_{1 \leq q \leq N} c(q) \}.$$

inputFormat

The input is read from standard input. The first line contains a single integer Q representing the number of test cases. For each test case, the first line contains two integers N and M separated by a space. Then, M subsequent lines follow each containing two integers U and P, where U is the user ID and P is the product ID.

outputFormat

For each test case, output the ID of the most popular product on a separate line to standard output.

## sample
2
5 6
1 1
2 2
1 2
3 2
2 3
3 1
3 4
1 1
1 2
2 2
2 1
2

1

</p>