Train Ticket Allocation

No attempts yetTime limit1sMemory limit256 MB

Problem

A train starts at station 1, passes the stations in increasing order and stops at station NN. A ticket from station ii to station jj can be sold whenever i<ji < j.

The law fixes the price CijC_{ij} of a ticket from station ii to station jj in advance, and the exact demand DijD_{ij} for that pair is known before the trip, so you may sell anywhere from 0 to DijD_{ij} tickets for it. The government also sets aside OijO_{ij} free tickets from station ii to station jj. A passenger holding one of those takes a seat but brings no income.

The train carries PP passengers at most. On every segment between two adjacent stations the number of passengers on board, counting the ones with government tickets, must not exceed PP. Selling beyond the capacity is not allowed.

Find the largest income the trip can produce.

Input

The first line contains the number of test cases TT.

Each test case begins with a line holding the number of stations NN and the train capacity PP. The next N1N-1 lines give the ticket prices. Line ii of that block holds NiN-i numbers, and its jj-th number is Ci,i+jC_{i,i+j}, the price of a ticket from station ii to station i+ji+j. The next N1N-1 lines give the demands DijD_{ij} in the same format, and the N1N-1 lines after those give the number of free government tickets OijO_{ij}, again in the same format.

  • 0<T1000 < T \le 100
  • 3N163 \le N \le 16
  • 0<P2000 < P \le 200
  • 0<Cij10000 < C_{ij} \le 1000
  • 0Dij2500 \le D_{ij} \le 250
  • 0Oij200 \le O_{ij} \le 20
  • The government tickets alone never exceed the capacity.

Output

For each test case, print the maximum possible income on its own line.