#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue> using namespace std; typedef long long LL;
const int maxn = 1e5+;
int T,N,cnt;
LL M; struct node{
LL money,time;
node(){}
node(LL a,LL b){money=a;time=b;}
bool operator < (const node &b) const
{return time > b.time;}
}; struct item
{
LL V,R,time;
item(){}
item(LL a,LL b,LL c){V = a;R = b;time = c;}
bool operator < (const item &b) const
{return R < b.R;}
}items[maxn]; LL bfs()
{
priority_queue<node> pq;
node st(,),cur;
pq.push(st);
int i,x=;
while(!pq.empty())
{
cur = pq.top();pq.pop();
if(cur.money >= M) return cur.time;
for(i=x;i<=cnt;i++)
{
if(cur.money < items[i].R) break;
if(cur.money>=items[i].R&&cur.money<items[i].V)
{
pq.push(node(items[i].V,cur.time+items[i].time));
}
}
x = i;
}
return -;
} int main()
{
cin >> T;
for(int cas=;cas<=T;cas++)
{
cin >> N >> M;
LL v,r,t;
cnt=;
for(int i=;i<N;i++)
{
cin >> v >> r >> t;
if(v==r) continue;
items[cnt++] = item(v,r,t);
}
sort(items+,items+cnt+);
cout << "Case #"<<cas<<": "<<bfs()<<endl;
}
}