#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
#include <cfloat>
#include <iomanip>
#include <stack>
#include <bitset>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define bitcount(n) __builtin_popcountll(n)
#define pii pair<int, int>
typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
const int N = 1000000 + 8;
const int M = 1500 + 7;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * (inf - 1);
const double pi = acos(-1);
const double eps = 1e-6;
const bool multipleTest = true;
ll L[N];
int a[N], b[N], cost[N];
int id[N];
bool cmp(int u, int v) {
if (cost[u] != cost[v]) return cost[u] < cost[v];
return mk(a[u], b[u]) < mk(a[v], b[v]);
}
int n, m, D;
ll q[N]; int top, bot;
void solve() {
cin >> n >> m >> D;
for(int i = 0; i < n; ++i) {
scanf("%d%d%d", a + i, b + i, cost + i);
id[i] = i;
}
sort(id, id + n, cmp);
L[0] = 0;
for(int i = 1; i <= D; ++i) L[i] = linf;
top = 0, bot = 0;
for(int i = 0; i < n; ++i) {
int u = id[i];
top = bot = 0;
int last = D;
for(int j = D; j >= a[u]; --j) {
while (top < bot && q[top] > j - a[u]) ++top;
last = min(last, j - a[u]);
while (last >= max(0, j - b[u])) {
while (top < bot && L[q[bot - 1]] >= L[last]) bot--;
q[bot++] = last--;
}
L[j] = min(L[j], L[q[top]] + cost[u]);
}
}
// for(int j = 0; j <= D; ++j) {
// cout << L[j] << ' ';
// }
// puts("");
if (L[D] <= m) printf("%lld\n", L[D]);
else puts("IMPOSSIBLE");
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
clock_t t1 = clock();
#endif
// createTest();
// return 0;
freopen("out.txt", "w", stdout);
int Test = 1;
if (multipleTest) {
cin >> Test;
}
for(int i = 0; i < Test; ++i) {
printf("Case #%d: ", i + 1);
solve();
}
//
#ifndef ONLINE_JUDGE
// cout<<"\n" << 1.0 * (clock() - t1) / CLOCKS_PER_SEC<<endl;
#endif
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8Y29tcGxleD4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjZmxvYXQ+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxiaXRzZXQ+CiAKIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIHJlcChpLCBhLCBiKSBmb3IoaW50IGkgPSAoYSk7IGkgPCAoYik7IGkrKykKI2RlZmluZSByZXBkKGksIGEsIGIpIGZvcihpbnQgaSA9IChhKTsgaSA+IChiKTsgaS0tKQojZGVmaW5lIGZvckl0KGl0LCBhKSBmb3IoX190eXBlb2YoKGEpLmJlZ2luKCkpIGl0ID0gKGEpLmJlZ2luKCk7IGl0ICE9IChhKS5lbmQoKTsgaXQrKykKI2RlZmluZSBmb3JSZXYoaXQsIGEpIGZvcihfX3R5cGVvZigoYSkucmJlZ2luKCkp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gdikgewogICAgaWYgKGNvc3RbdV0gIT0gY29zdFt2XSkgcmV0dXJuIGNvc3RbdV0gPCBjb3N0W3ZdOwogICAgcmV0dXJuIG1rKGFbdV0sIGJbdV0pIDwgbWsoYVt2XSwgYlt2XSk7Cn0KIAppbnQgbiwgbSwgRDsKIApsbCBxW05dOyBpbnQgdG9wLCBib3Q7CiAKdm9pZCBzb2x2ZSgpIHsKICAgIGNpbiA+PiBuID4+IG0gPj4gRDsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBzY2FuZigiJWQlZCVkIiwgYSArIGksIGIgKyBpLCBjb3N0ICsgaSk7CiAgICAgICAgaWRbaV0gPSBpOwogICAgfQogICAgc29ydChpZCwgaWQgKyBuLCBjbXApOwogCiAgICBMWzBdID0gMDsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gRDsgKytpKSBMW2ldID0gbGluZjsKIAogICAgdG9wID0gMCwgYm90ID0gMDsKIAogICAgZm9yKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIGludCB1ID0gaWRbaV07CiAKICAgICAgICB0b3AgPSBib3QgPSAwOwogICAgICAgIGludCBsYXN0ID0gRDsKIAogICAgICAgIGZvcihpbnQgaiA9IEQ7IGogPj0gYVt1XTsgLS1qKSB7CiAgICAgICAgICAgIHdoaWxlICh0b3AgPCBib3QgJiYgcVt0b3BdID4gaiAtIGFbdV0pICsrdG9wOwogICAgICAgICAgICBsYXN0ID0gbWluKGxhc3QsIGogLSBhW3VdKTsKICAgICAgICAgICAgd2hpbGUgKGxhc3QgPj0gbWF4KDAsIGogLSBiW3VdKSkgewogICAgICAgICAgICAgICAgd2hpbGUgKHRvcCA8IGJvdCAmJiBMW3FbYm90IC0gMV1dID49IExbbGFzdF0pIGJvdC0tOwogICAgICAgICAgICAgICAgcVtib3QrK10gPSBsYXN0LS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgTFtqXSA9IG1pbihMW2pdLCBMW3FbdG9wXV0gKyBjb3N0W3VdKTsKICAgICAgICB9CiAgICB9CiAKLy8gICAgZm9yKGludCBqID0gMDsgaiA8PSBEOyArK2opIHsKLy8gICAgICAgIGNvdXQgPDwgTFtqXSA8PCAnICc7Ci8vICAgIH0KLy8gICAgcHV0cygiIik7CiAKICAgIGlmIChMW0RdIDw9IG0pIHByaW50ZigiJWxsZFxuIiwgTFtEXSk7CiAgICBlbHNlIHB1dHMoIklNUE9TU0lCTEUiKTsKIAp9CiAKIAogCmludCBtYWluKCkgewojaWZuZGVmIE9OTElORV9KVURHRQogICAgZnJlb3BlbigiaW4udHh0IiwgInIiLCBzdGRpbik7CiAgICBjbG9ja190IHQxID0gY2xvY2soKTsKI2VuZGlmCiAgICAvLyAgICAgICAgY3JlYXRlVGVzdCgpOwogICAgLy8gICAgICAgIHJldHVybiAwOwogICAgICAgIGZyZW9wZW4oIm91dC50eHQiLCAidyIsIHN0ZG91dCk7CiAKIAogCiAKICAgIGludCBUZXN0ID0gMTsKICAgIGlmIChtdWx0aXBsZVRlc3QpIHsKICAgICAgICBjaW4gPj4gVGVzdDsKICAgIH0KIAogICAgZm9yKGludCBpID0gMDsgaSA8IFRlc3Q7ICsraSkgewogICAgICAgICAgICAgICAgcHJpbnRmKCJDYXNlICMlZDogIiwgaSArIDEpOwogICAgICAgIHNvbHZlKCk7CiAgICB9CiAgICAvLwojaWZuZGVmIE9OTElORV9KVURHRQovLyAgICBjb3V0PDwiXG4iIDw8IDEuMCAqIChjbG9jaygpIC0gdDEpIC8gQ0xPQ0tTX1BFUl9TRUM8PGVuZGw7CiNlbmRpZgogCn0=