This page is still under construction.

Parts of this page are still being built. What you see may change.

Milo of Croton and the Calf

Interview

Time limit1sMemory limit256 MB

Summary
Simulate Milo lifting the calf as it gains a pound a day, with strength gains after 3 days and soreness lasting 2 days, and report the first failure day.
Level

Easy2 of 10

Topics
Simulation
Solved
No attempts yet

Problem

Milo of Croton was a wrestler who won the Olympic games six times and was famous for his strength. The story goes that he held up the ceiling of a collapsing building until Pythagoras was safely out. One of the ways he built that strength was a training regimen: he carried a calf around the village once a day, and he kept it up until the calf had grown into a full bull.

This problem looks at Milo's regimen a little more carefully. Carrying a young bull around the village has two effects. He is sore for the next few days and can lift less weight, and he builds muscle that lets him lift more weight later. For each day, equivalently for each weight of the calf, you are given two numbers: a permanent strength increase that kicks in 3 days after the exercise, and a soreness penalty that applies on the next 2 days after the exercise. Both the strength increases and the soreness penalties are cumulative. If Milo exercises two days in a row, then on the day after that he is sore from both, and on the second day after that he is sore only from the second exercise while the strength from the first one has arrived.

You are told how much the calf weighed on the first day, how much Milo could lift on the first day, how many days Milo wants to exercise, and what the exercise effects are at each weight of the calf. When Milo's ability to lift equals the weight of the calf he lifts it successfully, but when it is strictly less he fails. Milo exercises every day, and the calf gains one pound every day. Determine whether Milo can finish his entire regimen, and if not, on what day he first fails.

Input

The first line contains the number KK of data sets. The KK data sets follow, each in the form below.

The first line of a data set contains three integers ww, cc, dd separated by spaces. ww is the weight Milo can lift on day 1, with 0≤w≤10000 \le w \le 1000. cc is the weight of the calf on day 1, with 0≤c≤10000 \le c \le 1000. dd is the number of days Milo plans to exercise, with 1≤d≤1001 \le d \le 100.

Then dd lines follow. Line i=1,…,di = 1, \dots, d describes the effect of carrying the calf around the village when it weighs c+i−1c + i - 1, that is, on day ii. It contains two integers gig_i, sis_i. gig_i is the permanent strength gain from carrying the calf, which kicks in on day i+3i + 3, with 0≤gi≤10000 \le g_i \le 1000. sis_i is the soreness penalty, which reduces how much he can lift on days i+1i + 1 and i+2i + 2, with 0≤si≤1000 \le s_i \le 100.

Output

For each data set, output Data Set x: on a line by itself, where xx is the number of that data set.

If Milo can finish his entire regimen, output Completed successfully. Otherwise output the number of the first day on which Milo cannot carry the calf any more.

Follow each data set with a blank line.

Examples6

  1. Example 1

    Input
    2
    150 130 4
    10 8
    8 8
    8 11
    9 20
    131 130 3
    10 0
    10 0
    10 0
    
    Expected output
    Data Set 1:
    Completed successfully.
    
    Data Set 2:
    3
    
  2. Example 2

    Input
    1
    0 0 1
    0 0
    
    Expected output
    Data Set 1:
    Completed successfully.
    
  3. Example 3

    Input
    1
    0 1 1
    0 0
    
    Expected output
    Data Set 1:
    1
    
  4. Example 4

    Input
    1
    10 10 3
    0 5
    0 0
    0 0
    
    Expected output
    Data Set 1:
    2
    
  5. Example 5

    Input
    1
    20 18 5
    0 1
    0 1
    0 0
    0 0
    0 0
    
    Expected output
    Data Set 1:
    3
    
  6. Example 6

    Input
    1
    100 97 8
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    
    Expected output
    Data Set 1:
    Completed successfully.