Manage your Energy (Small)

Allocate limited energy across ordered activities, regaining R after each up to cap E, to maximize value times energy spent.

Medium4Dynamic programmingInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Your calendar today is packed with important things to do. You prepared carefully, so none of the activities overlap. Now it is morning, and you are worried that your enthusiasm will run ahead of your energy.

You have to manage that energy. You start the day with a full tank of EE joules. You may never go below zero joules, or you drop from exhaustion. On each activity you may spend any non-negative integer number of joules (spend zero if you feel lazy), and after each activity you regain RR joules. No matter how lazy you are, your energy can never exceed EE joules, and any energy you would regain past that point is wasted.

Some things matter more than others. The ii-th activity has a value viv_i that says how important it is to you. The gain from an activity is its value multiplied by the number of joules you spend on it. Manage your energy so that the total gain is as large as possible.

You cannot reorder the activities in your calendar. The order is fixed, and only the split of energy is up to you.

Input

The first line contains the number of test cases TT. TT test cases follow. Each test case is described by two lines.

The first line contains three integers EE, RR, and NN. EE is the maximum and initial amount of energy, RR is the amount you regain after each activity, and NN is the number of activities planned for the day. The second line contains the values v1,v2,,vNv_1, v_2, \dots, v_N in order.

Limits

  • 1T1001 \le T \le 100
  • 1E51 \le E \le 5
  • 1R51 \le R \le 5
  • 1N101 \le N \le 10
  • 1vi101 \le v_i \le 10

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 gain you can achieve by managing your energy that day.

Hint

In the first sample case you spend all 5 joules on the first activity for a gain of 10, regain 2, and spend them on the second activity. In the second case you spend 2 joules on the first activity, regain them, and spend 5 on the second. In the third case the regain rate equals the maximum energy, so the tank is full again after every activity and you can spend the full 3 joules on each of the four activities.