#pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int maxn = 1005; long long dp[3005]; struct prob { int a, b, c; } p[maxn]; int main() { int T, n, t; scanf("%d", &T); while(T--) { scanf("%d%d", &n, &t); for(int i = 0; i < n; i++) scanf("%d%d%d", &p[i].a, &p[i].b, &p[i].c); for(int i = 0; i < n; i++) { for(int j = 1; j < n; j++) { if((long long)p[j - 1].c * p[j].b > (long long)p[j].c * p[j - 1].b) swap(p[j - 1], p[j]); } } memset(dp, 0, sizeof(dp)); for(int i = 0; i < n; i++) { for(int j = t - p[i].c; j >= 0; j--) { dp[j + p[i].c] = max(dp[j + p[i].c], dp[j] + p[i].a - (j + p[i].c) * p[i].b); } } long long ret = 0; for(int i = 0; i <= t; i++) ret = max(ret, dp[i]); printf("%I64d\n", ret); } return 0; }