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 N courses, and every course meets every day, because a programmer must not forget dynamic programming while learning computational geometry. Course i starts at time Ai and finishes at time Bi, and both endpoints count as class time. Course i has Si 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 M students, so course i occupies ⌈Si/M⌉ 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 i finishes in a room, cleaning that room before course j starts there takes cleanij time. So course j can follow course i directly in the same room only when Bi+cleanij<Aj.
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.
The first line has the number of test cases T. (T≤100)
The first line of each test case has the number of courses N and the capacity of one room M. (1≤N≤100, 1≤M≤10000)
Each of the next N lines has the start time Ai, the finish time Bi, and the number of registered students Si of course i. (0≤Ai≤Bi≤107, 1≤Si≤10000)
Each of the next N lines has one row of the cleaning time matrix. The j-th integer of the i-th row is cleanij. (0≤cleanij≤107, cleanii=0)
For each test case print one line in the form Case x: y, where x is the test case number starting from 1 and y is the minimum number of rooms to hire.