Pearls

No attempts yetTime limit1sMemory limit128 MB

Problem

In Pearlania, everybody is fond of pearls. A company called The Royal Pearl produces a great deal of pearl jewelry. It delivers to the royal family, but it also makes bracelets and necklaces for ordinary people, using pearls of much lower quality.

Pearls are separated into 100 quality classes. Each class is identified by the price of a single pearl in that class; this price is unique to the class. A higher-quality class always costs more per pearl than a lower one.

Every month the stock manager prepares a list of how many pearls are needed in each quality class. The pearls are bought on the local pearl market. In addition to the per-pearl price, every completed purchase in a class costs an extra amount equal to the price of ten pearls of that class (this surcharge discourages buying just a single pearl). So buying aa pearls in a class whose price is pp costs (a+10)×p(a + 10)\times p.

To save money, the CFO may buy pearls in a higher quality class than requested, but never in a lower one. Customers do not mind receiving better pearls as long as the price stays the same. Merging several classes into one higher-class purchase can reduce the total surcharge.

For example, suppose 5 pearls are needed in the 10-Euro class and 100 pearls in the 20-Euro class. Buying them separately costs (5+10)×10+(100+10)×20=2350(5 + 10)\times 10 + (100 + 10)\times 20 = 2350 Euro. Buying all 105 pearls in the 20-Euro class costs only (5+100+10)×20=2300(5 + 100 + 10)\times 20 = 2300 Euro.

Given the number of pearls needed and the price per pearl for several quality classes, compute the lowest possible total price to buy everything on the list. Pearls may be bought in the requested class or in any higher class, but never in a lower one.

Input

The first line contains the number of test cases.

Each test case begins with a line containing the number of quality classes cc (1c1001 \le c \le 100). Then follow cc lines, each with two integers aia_i and pip_i: the number of pearls aia_i needed in that class (1ai10001 \le a_i \le 1000) and the price per pearl pip_i in that class (1pi10001 \le p_i \le 1000). The classes are listed in ascending order of quality, and therefore of price. All numbers in the input are integers.

Output

For each test case, output a single line containing one integer: the lowest possible total price needed to buy everything on the list.