Best coffee (Small)

Pick one coffee cup per day from kinds with limited cups and expiry days to maximize total satisfaction over K days.

Medium5GreedySortingInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Hyein starts his day by drinking coffee in the morning.

He has NN kinds of coffee. Kind ii has cic_i cups left, and it expires on day tit_i counting from today. Every cup of kind ii (1iN1 \le i \le N) that he drinks gives him satisfaction sis_i. He cannot drink coffee after its expiry date, but he can still drink it on day tit_i itself. For example, if ti=1t_i = 1, he either drinks that coffee today or gives it up.

Hyein drinks only one cup a day, and only in the morning. On a day when no drinkable coffee is left, he gains no satisfaction.

Find the maximum total satisfaction he can gain from today through day KK.

Input

The first line contains the number of test cases TT. Then TT test cases follow.

The first line of each test case contains the number of coffee kinds NN and the number of days KK, separated by one space. The next NN lines give the remaining cups, the expiry day, and the satisfaction of each kind in this format.

ci ti si

Constraints

  • 1T1001 \le T \le 100
  • 1N81 \le N \le 8
  • 1K81 \le K \le 8
  • 1ciK1 \le c_i \le K
  • 1tiK1 \le t_i \le K
  • 1si10001 \le s_i \le 1000

Output

For each test case, print one line in the following format.

Case #X: Y

XX is the test case number starting from 1, and YY is the maximum total satisfaction Hyein can gain.