A monitor election is going to be held in your class. There are students in your class. And you want all your classmates to vote for you.
There exist two ways to convince each of your classmates to vote for you. The first way to convince your -th classmate is to pay him/her coins. The other way is to make other classmates vote for you, and the -th classmate will vote for you for free.
It should be noticed that the voting takes places in several steps. For example, if you have four classmates with , then if you buy the vote of the -th classmate, then all your classmates will vote for you. And the set of classmates vote for you changes as: .
Please calculate the minimum coins you need to spend so that all your classmates will vote for you.
the first line contains one integer , representing the number of test cases.
The first line of each test case contains one integer , representing the number of your classmates.
The next lines contains two integers each line, and .
Hint: It is guaranteed that the sum of over all test cases does not exceed .
For each test case print one integer , representing the answer.
3
7
0 1
3 1
1 1
6 1
1 1
4 1
4 1
3
1 5
2 10
2 8
6
2 6
2 3
2 8
2 7
4 4
5 5
For 40% testcases, for two classmates and , if and only if .