Robberies

No attempts yetTime limit1sMemory limit256 MB

Problem

Roy plans to rob banks for a short while, then retire to a quiet job at a university. For months he has measured how much cash each bank holds and how risky it is to rob it.

His mother Ola set a limit on the risk she tolerates. Roy may rob any set of the banks, each bank at most once, as long as the probability that he is caught stays strictly below that limit. The banks are independent, so if he robs the set SS of banks, the probability of getting caught is 1jS(1Pj)1 - \prod_{j \in S} (1 - P_j).

Find the largest total amount of money Roy can take.

Input

The first line contains the number of test cases TT.

Each test case starts with a line holding a real number PP and an integer NN. PP is the limit Roy must stay below and NN is the number of banks he has plans for. Each of the next NN lines holds an integer MjM_j and a real number PjP_j. Bank jj holds MjM_j millions, and robbing it has probability PjP_j of getting caught.

  • 0<T1000 < T \le 100
  • 0.0P1.00.0 \le P \le 1.0
  • 0<N1000 < N \le 100
  • 0<Mj1000 < M_j \le 100
  • 0.0Pj1.00.0 \le P_j \le 1.0
  • Every real number in the input has at most two digits after the decimal point.

A bank goes bankrupt once it is robbed, so Roy robs each bank at most once.

Output

For each test case print one line with the largest number of millions Roy can take while the probability of getting caught stays strictly below PP. If no set of banks meets that requirement, print 0.