beecrowd | 2004

Enisvaldo's Hunger

By João Vitor Martins, UECE BR Brazil

Timelimit: 1

Enisvaldo always been a very skinny boy. He always ate little, and ate only bread with egg. One day he went to the doctor and discovered that he had a kidney stone that had to be surgically removed.

He decided it was time to change your diet, and eat properly. He went to the nutritionist, who gave him several tips. It is harmful to health consume more than 100g or less than 10g of the same type of food per day. But if you can not consume the right amount, it should preferably eat as much as possible the type of food.

The nutritionist also said it is very important to eat as much as possible of different types of food. The Enisvaldo mother always did the shopping for him, but this time he wanted to do the shopping for choosing foods he will eat that day. Enisvaldo was doing the shopping but realized he had little money, so he could only buy one of each food type, but he wanted to consume the largest amount of food possible.

As Enisvaldo is unable to find out the amount in grams of food that he can consume, thus you should to help him. Given a list of foods, each with its respective food type and weight, you should to say the maximum quantity in grams which Enisvaldo should consume. Remember, Enisvaldo can eat only one food for each type.

Input

The first input line contains a value of Q, which is the amount of test cases. The first line of each test case contains an integer N (1 ≤ N ≤ 1000) representing the amount of different foods at the supermarket. Each of the next N contains two integers T (1 ≤ T≤ 100) and P ( 1 ≤ P ≤ 1000 ), representing the type and weight of food, respectively.

Output

For each case, you should to print larger amount of food in grams that Enisvaldo should consume.

Input Sample Output Sample

2
8
1 10
1 101
2 3
2 10
2 86
2 90
3 2
3 5
1
1 1

105
1