Morning Coffee (Large)

Choose one cup per day from day 1 to K so no kind is drunk past its deadline and total satisfaction is largest.

Medium5GreedyHeapSortingInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Kokoa starts every morning with a cup of coffee.

Her cupboard holds NN kinds of coffee. Kind ii has cic_i cups left, and counting today as day 1, it can be drunk up to day tit_i. Coffee past its date cannot be drunk, but day tit_i itself is still fine. If ti=1t_i = 1, that coffee has to be drunk today or thrown away.

One cup of kind ii gives satisfaction sis_i. Kokoa drinks one cup a day and only in the morning. On a day with no coffee left she gains no satisfaction. Find the largest total satisfaction she can collect from day 1 through day KK.

Input

The first line holds the number of test cases TT. TT test cases follow.

Each test case starts with a line holding two positive integers separated by one space: the number of coffee kinds NN and the number of days KK to compute the answer over. The next NN lines describe one kind each, giving the cups left, the last drinkable day, and the satisfaction in this format.

ci ti si

The value ranges are as follows.

  • 1T1001 \le T \le 100
  • 1N1001 \le N \le 100
  • 1K2×10121 \le K \le 2 \times 10^{12}
  • 1ciK1 \le c_i \le K
  • 1tiK1 \le t_i \le K
  • 1si10001 \le s_i \le 1000

KK can exceed the range of a 32 bit integer.

Output

For each test case print one line in this format.

Case #X: Y

XX is the test case number starting at 1, and YY is the largest total satisfaction.