#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define vll vector<ll>
#define G vector<vll >
#define gg vector<int>
#define F first
#define S second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
#define clr(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
#define rll read_ll();
#define gc getchar
#define pc putchar
typedef long long ll;
template<class T> inline T lcm(T a,T b){
        return a/gcd(a,b)*b;
}
template<typename T>
void debug(T first) {
    cout << first << "\n";
}
template<typename T, typename... Args>
void debug(T first, Args... args) {
    cout << first << " ";
    debug(args...);
}


ll read_ll(){char c=gc();while((c<'0'||c>'9')&&c!='-')c=gc();ll ret=0;int neg=0;if(c=='-')neg=1,c=gc();while(c>='0'&&c<='9'){ret=10*ret+c-48;c=gc();}return neg?-ret:ret;}


typedef long double ld;
const ld inf = 1e18;

struct chtDynamic {  
	struct line {
		ll m, b; ld x,s; 
		ll val; bool isQuery; 
		line(ll _m = 0, ll _b = 0, ll _s = 0) : 
			m(_m), b(_b), val(0), x(-inf), s(_s), isQuery(false) {} 
		
		ll eval(ll x) const { return m * (x-s) + b;	}
		bool parallel(const line &l) const { return m == l.m; }
		ld intersect(const line &l) const {
			return parallel(l) ? inf : 1.0 * (l.b - b) / (m - l.m);
		}
		bool operator < (const line &l) const {
			if(l.isQuery) return x < l.val;
			else return m < l.m; 
		}
	};

	set<line> hull; 
	typedef set<line> :: iterator iter; 

	bool cPrev(iter it) { return it != hull.begin(); }
	bool cNext(iter it) { return it != hull.end() && next(it) != hull.end(); }

	bool bad(const line &l1, const line &l2, const line &l3) {
		return l1.intersect(l3) <= l1.intersect(l2); 
	}
	bool bad(iter it) {
		return cPrev(it) && cNext(it) && bad(*prev(it), *it, *next(it));
	}

	iter update(iter it) {
		if(!cPrev(it)) return it; 
		ld x = it -> intersect(*prev(it));
		line tmp(*it); tmp.x = x; tmp.s = it->s;
		it = hull.erase(it); 
		return hull.insert(it, tmp);
	}

	void addLine(ll m, ll b, ld s) { 
		line l(m, b, s); 
		iter it = hull.lower_bound(l); 
		if(it != hull.end() && l.parallel(*it)) {
			if(it -> b < b) it = hull.erase(it); 
			else return;
		}
		it = hull.insert(it, l); 
		if(bad(it)) return (void) hull.erase(it);

		while(cPrev(it) && bad(prev(it))) hull.erase(prev(it));
		while(cNext(it) && bad(next(it))) hull.erase(next(it));

		it = update(it);
		if(cPrev(it)) update(prev(it));
		if(cNext(it)) update(next(it));
	}

	ll query(ll x) const { 
		if(hull.empty()) return -inf;
		line q; q.val = x, q.isQuery = 1;
		iter it = --hull.lower_bound(q);
		return it -> eval(x);
	}
} ;

class Machine {
public:
	ll Day, Price, Resale, MoneyPerDay;
	Machine() {
		
	}

};
void solve(ll N, ll C, ll D, int &tc) {
	chtDynamic ds;
	vector<Machine> m(N);
	FOR(i,0,N-1) {
		cin>>m[i].Day>>m[i].Price>>m[i].Resale>>m[i].MoneyPerDay;
	}
	sort(all(m),[](Machine a, Machine b) {
		return a.Day < b.Day;
	});
	ll MaxMoney = C;
	// if(tc!=47&&tc!=48) 
	// {
	for(auto machine : m) {
		if(machine.MoneyPerDay == 0) continue;
		MaxMoney = max(MaxMoney, ds.query(machine.Day-1));
		if(machine.Price > MaxMoney) continue;
		ll PrevMoney = MaxMoney - machine.Price + machine.Resale;
		ds.addLine(machine.MoneyPerDay,PrevMoney,(ld)(machine.Day*1.0));
	}
	printf("Case %d: %lld\n", tc, max(MaxMoney,ds.query(D)));
	// }
	tc++;
}
int main()
{
	int tc = 1;
	while(1) {
		bool ok = true;
		int N,C,D;
		cin>>N>>C>>D;
		if(N==0) break;
		solve(N,C,D,tc);
	}
	return 0;
}