#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbGIgbG93ZXJfYm91bmQKI2RlZmluZSB1cCB1cHBlcl9ib3VuZAojZGVmaW5lIHZsbCB2ZWN0b3I8bGw+CiNkZWZpbmUgRy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