#UnknownID34. XHXMMMlOPUkTFF#**$?

XHXMMMlOPUkTFF#**$?

Statement

Arseniy came up with another business plan — to sell soda from a vending machine! For this, he purchased a machine with n n shelves, as well as k k bottles, where the i i -th bottle is characterized by the brand index bi b_i and the cost ci c_i .

You can place any number of bottles on each shelf, but all bottles on the same shelf must be of the same brand.

Arseniy knows that all the bottles he puts on the shelves of the machine will be sold. Therefore, he asked you to calculate the maximum amount he can earn.

Format

Input

The first line contains one integer t t ( 1t104 1 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains two integers n n and k k ( 1n,k2105 1 \le n, k \le 2 \cdot 10^5 ), where n n is the number of shelves in the machine, and k k is the number of bottles available to Arseniy.

The next k k lines contain two integers bi b_i and ci c_i ( 1bik,1ci1000 1 \le b_i \le k, 1 \le c_i \le 1000 ) — the brand and cost of the i i -th bottle.

It is also guaranteed that the sum of n n across all test cases does not exceed 2105 2 \cdot 10^5 and that the sum of k k across all test cases also does not exceed 2105 2 \cdot 10^5 .

Output

For each test case, output one integer — the maximum amount that Arseniy can earn.

Sample

4
3 3
2 6
2 7
1 15
1 3
2 6
2 7
1 15
6 2
1 7
2 5
190000 1
1 1000
28
15
12
1000