SP19551 CWORLD - A Colorful world

Description

This is the hardest level of the game. There are n stages in the level. In each stage you will given qi balls. The color of the balls are denoted by an integer between 1 to k. You can pick up **not more than one** ball in each stage. (You can skip if you want) If you pick up a ball you will gain or lose some points depending on the last ball you have picked. You know color of the available balls of each stage and points you'll get for a certain combination, now can you figure out the maximum point you can get? **Note that you wont gain or lose any point for the first ball you picked.** One stage can contain multiple balls of same color. **Input Specification:** First line of input will contain number of test cases T. In each case first line will contain two integer n and k. Than there will be n lines which describes each stage. Each line contains an integer qi which denotes number of balls available in ith level and then q $ _{i} $ integers will denote the colors. Then there will be a k lines, each containing k integer, j $ ^{th} $ integer of i $ ^{th} $ line will indicate the point you will gain or lose if you pick a ball of color j after color i. Negative means you will lose point. **Output Specification:** Print case number and a single integer denoting the maximum point you can get. **Constraints:** T

Input Format

N/A

Output Format

N/A