eolymp
bolt
Try our new interface for solving problems
Problems

How Much?

How Much?

This financial crisis! Even MI6’s technology department does not escape the consequences. With all those constraints on the budget, how can R be expected to supply our spies with cars equipped with all the technological gadgets and weaponry they need to save the world? As if it is not hard enough to put all those tracking systems, oil sprayers, guns, bullets and missiles in one car, now R has to worry about the costs as well.

The management insists, though: before R is allowed to order a car and all the parts he needs, he will first need to determine the exact amount of money that he needs. Management will then decide whether he gets to realize his vision or not.

This sort of bureaucratic nonsense is not something that R wants to waste any time on. He therefore wants you to help him. Given the price of the car, a listing of the parts R wants to install, and the price per piece of each part, work out what the total cost is of the project.

Input

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with an integer s (1s100000): the stock price of the car.
  • one line with an integer n (0n1000): the number of different parts to be installed.
  • n lines with two space-separated integers qi and pi (1qi100 and 1pi10000): for each different part i, the number of pieces qi required of such part, and the price pi for a single piece.

Output

For each test case print one line with an integer: the total amount of money needed to buy the car and all the parts.

Time limit 1 second
Memory limit 64 MiB
Input example #1
2
10000
2
1 2000
3 400
50000
0
Output example #1
13200
50000
Source 2013 Benelux Algorithm Programming Contest (BAPC), Preliminaries, September 28, Problem H