Last Hit (Small)

Choose which monster to shoot or when to pass on each turn so your shots land the killing blow on the most valuable monsters before the tower kills them.

Medium6Dynamic programmingGame theorySimulationNo attempts yetTime limit5sMemory limit512 MB

Problem

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

A shot from Diana lowers the target's hit points by PP, and a shot from the tower lowers them by QQ. A monster whose hit points drop below 1 is dead. The ii-th monster starts with HiH_i hit points. If the shot that kills the ii-th monster is Diana's, she receives GiG_i gold; if it is the tower's, she receives nothing. Find the maximum 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 three space-separated integers PP, QQ and NN. Then NN lines follow, and the ii-th of them contains two space-separated integers HiH_i and GiG_i.

The monsters are given in order of their distance from the tower, nearest first. The tower shoots the ii-th monster only after every monster before it is dead.

Constraints

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

Output

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

Hint

In the second test case of the sample, Diana gives up the first monster and leaves it to the tower. She spends her first two turns on the third monster, cutting it down to 80 hit points, and that lets her land the killing shot on both the second and the third monster.