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 a pearls in a class whose price is p costs (a+10)×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 Euro. Buying all 105 pearls in the 20-Euro class costs only (5+100+10)×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.
The first line contains the number of test cases.
Each test case begins with a line containing the number of quality classes c (1≤c≤100). Then follow c lines, each with two integers ai and pi: the number of pearls ai needed in that class (1≤ai≤1000) and the price per pearl pi in that class (1≤pi≤1000). The classes are listed in ascending order of quality, and therefore of price. All numbers in the input are integers.
For each test case, output a single line containing one integer: the lowest possible total price needed to buy everything on the list.