It Can Be Arranged

No attempts yetTime limit2sMemory limit128 MB

Problem

Every year several universities host national programming contests. Dhaka holds an ICPC regional contest every year, and one or two teams from it go to the ICPC World Finals.

After watching those contests, MMR (Mission Maker Rahman) decided to open a programming school. The school teaches NN courses, and every course meets every day, because a programmer must not forget dynamic programming while learning computational geometry. Course ii starts at time AiA_i and finishes at time BiB_i, and both endpoints count as class time. Course ii has SiS_i registered students, and no student is registered for two courses.

MMR wants to hire rooms in a building called Sentinel Tower. One room holds at most MM students, so course ii occupies Si/M\lceil S_i / M \rceil rooms at the same time and runs the same class separately in each of them.

Programmers are restless and they leave a mess. Once course ii finishes in a room, cleaning that room before course jj starts there takes cleanij\text{clean}_{ij} time. So course jj can follow course ii directly in the same room only when Bi+cleanij<AjB_i + \text{clean}_{ij} < A_j.

Every course repeats at the same time each day, so you plan a single day. Find the minimum number of rooms MMR has to hire.

Input

The first line has the number of test cases TT. (T100T \le 100)

The first line of each test case has the number of courses NN and the capacity of one room MM. (1N1001 \le N \le 100, 1M100001 \le M \le 10000)

Each of the next NN lines has the start time AiA_i, the finish time BiB_i, and the number of registered students SiS_i of course ii. (0AiBi1070 \le A_i \le B_i \le 10^7, 1Si100001 \le S_i \le 10000)

Each of the next NN lines has one row of the cleaning time matrix. The jj-th integer of the ii-th row is cleanij\text{clean}_{ij}. (0cleanij1070 \le \text{clean}_{ij} \le 10^7, cleanii=0\text{clean}_{ii} = 0)

Output

For each test case print one line in the form Case x: y, where xx is the test case number starting from 1 and yy is the minimum number of rooms to hire.