#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 shelves, as well as bottles, where the -th bottle is characterized by the brand index and the cost .
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 ( ) — the number of test cases.
The first line of each test case contains two integers and ( ), where is the number of shelves in the machine, and is the number of bottles available to Arseniy.
The next lines contain two integers and ( ) — the brand and cost of the -th bottle.
It is also guaranteed that the sum of across all test cases does not exceed and that the sum of across all test cases also does not exceed .
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
相关
在下列比赛中: