시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB124342.857%

## 문제

Diana needs your help maximizing her gold while playing her favorite game. She is often faced with a scenario where she is standing close to her tower and is facing N monsters. When that happens, Diana and the tower take turns shooting the monsters, and she goes first. During her turn, Diana may choose a monster to shoot at (this means Diana may choose to skip a turn). During its turn, the tower shoots the monster closest to it. Diana and the tower can not shoot dead monsters.

If Diana shoots at a monster, its hit points are reduced by P. If the tower shoots at a monster, its hit points are reduced by Q. If a monster's hit points are reduced below 1, it is killed. The ith monster starts with Hi hit points. Diana is awarded Gi gold if her shot kills the ith monster, but none if the tower's shot kills it. What is the maximum amount of gold Diana can obtain?

## 입력

The first line of the input gives the number of test cases, T. T test cases follow. Each case begins with one line containing three space-separated integers representing P, Q and N. N lines then follow, with the ith line containing two space-separated integers representing Hi and Gi.

The monsters are given in the order of their distance from the tower. In other words, the tower will shoot at the ith monster only if all monsters < i are dead.

Limits

• 1 ≤ T ≤ 100
• 20 ≤ P ≤ 200
• 20 ≤ Q ≤ 200
• 1 ≤ Hi ≤ 200
• 0 ≤ Gi ≤ 106
• 1 ≤ N ≤ 100

## 출력

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the maximum amount of gold that Diana can obtain.

## 예제 입력 1

2
20 40 3
100 100
20 100
60 100
20 60 3
80 100
80 200
120 300


## 예제 출력 1

Case #1: 300
Case #2: 500


## 힌트

In the second example, Diana should give up the first monster. During her first two turns she should soften up the third monster bringing it down to 80 hp, allowing her to easily get the last shot on the second and the third monsters.

## 채점 및 기타 정보

• 예제는 채점하지 않는다.