#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MS(a, b) memset(a, b, sizeof a) #define LB(x) ((x) & (-x)) #define REP(a, b, c) for(int a = b; a < c; ++a) #define REP1(a, b, c) for(int a = b; a <= c; ++a) using namespace std; int dp[1005][3005]; struct P { int a,b,c; void in() { scanf("%d %d %d", &a, &b, &c);} bool operator<(const P &t) const { return t.b * c < b * t.c; } }no[1005]; int sum[1005]; int main() { #ifdef PIT freopen("1002.in","r",stdin); // freopen("1002.out","w",stdout); #endif int T; scanf("%d", &T); while(T--) { int n, t; scanf("%d %d",&n, &t); MS(dp, 0); REP1(i, 1, n) no[i].in(); sort(no+1, no+1+n); REP1(i, 0, n) for(int j = t; j >= 0; j--) { dp[i+1][j] = dp[i][j]; if(j + no[i+1].c <= t) dp[i+1][j+no[i+1].c] = max(dp[i+1][j+no[i+1].c], dp[i][j]+no[i+1].a - no[i+1].b*(j+no[i+1].c)); } int ans = 0; for(int i = 0; i <= t; i++) ans = max(ans, dp[n][i]); printf("%d\n",ans); } return 0; }