Last Hit

Choose which monsters to last-hit for gold while a tower shoots the closest living monster on its own turns.

Medium6Dynamic programmingMathNo attempts yetTime limit10sMemory limit512 MB

Problem

Diana wants to earn as much gold as she can in her favorite game. She is standing next to her own tower, facing NN monsters. Diana and the tower take turns attacking the monsters, and Diana attacks first. On her turn Diana may pick one living monster and shoot it, and she may also do nothing and pass the turn. On its turn the tower shoots the living monster closest to it. Neither Diana nor the tower attacks a dead monster.

A shot from Diana lowers the monster's hit points by PP, and a shot from the tower lowers them by QQ. A monster whose hit points drop below 11 dies. Monster ii starts with HiH_i hit points. If Diana's shot kills monster ii, she receives GiG_i gold. If the tower's shot kills it, she receives nothing. Find the largest amount of gold Diana can obtain.

Input

The first line contains the number of test cases TT. The first line of each test case contains PP, QQ and NN, separated by spaces. The ii-th of the next NN lines contains HiH_i and GiG_i, separated by a space.

The monsters are listed in order of their distance from the tower. The tower shoots monster ii only after every monster with a smaller number is dead.

Limits

  • 1T1001 \le T \le 100
  • 20P20020 \le P \le 200
  • 20Q20020 \le Q \le 200
  • 1N1001 \le N \le 100
  • 1Hi2001 \le H_i \le 200
  • 0Gi1060 \le G_i \le 10^6

Output

For each test case, print one line in the format Case #x: y, where xx is the test case number starting from 11 and yy is the largest amount of gold Diana can obtain.

Hint

In the sample test case with P=20P = 20 and Q=60Q = 60, Diana should give up the first monster. If she spends her first two turns on the third monster and brings it down to 8080 hit points, she takes the last hit on both the second and the third monster.