/* Check cf5-opt.vim defs.
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
VIM: let g:cppflags=g:Iboost.g:Itbb
VIM: let g:ldflags=g:Lboost.g:Ltbb.g:tbbmalloc.g:tbbmproxy
VIM: let g:ldlibpath=g:Bboost.g:Btbb
VIM: let g:argv=""
*/

/*
Problem B. Manage your Energy
This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
12 points	
Solve B-small
Judge's response for last submission: Correct.
Large input
23 points	
Solve B-large
Judge's response for last submission: Correct.
Problem

You've got a very busy calendar today, full of important stuff to do. You worked hard to prepare and make sure all the activities don't overlap. Now it's morning, and you're worried that despite all of your enthusiasm, you won't have the energy to do all of this with full engagement.

You will have to manage your energy carefully. You start the day full of energy - E joules of energy, to be precise. You know you can't go below zero joules, or you will drop from exhaustion. You can spend any non-negative, integer number of joules on each activity (you can spend zero, if you feel lazy), and after each activity you will regain R joules of energy. No matter how lazy you are, however, you cannot have more than E joules of energy at any time; any extra energy you would regain past that point is wasted.

Now, some things (like solving Code Jam problems) are more important than others. For the ith activity, you have a value vi that expresses how important this activity is to you. The gain you get from each activity is the value of the activity, multiplied by the amount of energy you spent on the activity (in joules). You want to manage your energy so that your total gain will be as large as possible.

Note that you cannot reorder the activities in your calendar. You just have to manage your energy as well as you can with the calendar you have.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case is described by two lines. The first contains three integers: E, the maximum (and initial) amount of energy, R, the amount you regain after each activity, and N, the number of activities planned for the day. The second line contains N integers vi, describing the values of the activities you have planned for today.

Output

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

Limits

1 ? T ? 100.
Small dataset

1 ? E ? 5.
1 ? R ? 5.
1 ? N ? 10.
1 ? vi ? 10.
Large dataset

1 ? E ? 107.
1 ? R ? 107.
1 ? N ? 104.
1 ? vi ? 107.
Sample


Input 
 	
Output 
 
3
5 2 2
2 1
5 2 2
1 2
3 3 4
4 1 3 5
Case #1: 12
Case #2: 12
Case #3: 39

In the first case, we can spend all 5 joules of our energy on the first activity (for a gain of 10), regain 2 and spend them on the second activity. In the second case, we spend 2 joules on the first activity, regain them, and spend 5 on the second. In the third case, our regain rate is equal to the maximum energy, meaning we always recover all energy after each activity - so we can spend full 3 joules on each activity.
*/

#include <iostream>
#include <sstream>
#include <iomanip>
#include <exception>
#include <stdexcept>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <string>
#include <memory>
#include <functional>
#include <algorithm>
#include <utility>
#include <limits>
#include <math.h>

using namespace std;

typedef std::vector<long long> vec;

long long energy; //energy	
long long regain; //regain
long long throughput; //regain

void rec( int beg, int end,  vec& v, vec& s, vec& c )
{
	if ( beg+1 >= end )
		return;

	int i = beg;
	for ( int j = beg+1; j < end; ++j )
		if ( v[j] > v[i] )
			i = j;
	
	long long needed = energy-c[i]-s[i];
	for ( int j = i-1; j >= beg && needed; --j)
	{
		if ( throughput-c[j] < needed )
			needed = throughput-c[j];
		long long m = min( s[j], needed );
		s[i] += m;
		s[j] -= m;
		for ( int k = j; k < i; ++k )
			c[k] += m;
		needed -= m;
	}

	rec(beg, i,v,s,c);
	rec(i+1,end,v,s,c);
}

void solve_puzzle()
{
	long long n; //activities
	cin >> energy >> regain >> n;

	if ( regain > energy )
		regain = energy;
	throughput = energy-regain;

	std::vector<long long> v;
	for (int i = 0; i < n; ++i )
	{
		long long x;
		cin >> x;
		v.push_back(x);
	}

	std::vector<long long> c(n,0); // amount energy that we pass
	std::vector<long long> s(n,regain); // spent energy
	s[0] = energy;

	rec(0,n,v,s,c);

	long long g = 0;
	long long e = energy;
	for ( int i = 0; i < n; ++i )
	{
		long long vg = v[i]*s[i];
		g += vg;
		e = e - s[i] + regain;
		if ( e > energy )
			std::cerr << "bug" << std::endl;
	}

	std::cout << g << std::endl;

//	std::cout << l << std::endl;
}

int main ( void )
{try{

	int puzzle_count;

	std::cin >>	puzzle_count;
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
	for ( int i = 1; i <= puzzle_count; i++ )
	{
		std::cout << "Case #" << i << ": ";
		solve_puzzle();
	}

	return 0;
}
catch ( const std::exception& e )
{
	std::cerr << std::endl
			<< "std::exception(\"" << e.what() << "\")." << std::endl;
	return 2;
}
catch ( ... )
{
	std::cerr  << std::endl
			<< "unknown exception." << std::endl;
	return 1;
}}
