Hippity Hopscotch

The game of hopscotch involves chalk, sidewalks, jumping, and picking things up. Our variant of hopscotch involves money as well. The game is played on a square grid of dimension n: each grid locationislabelled(p,q)where0≤p<nand0≤q<n. Eachgridlocationhasonitastackof between 0 and 100 pennies. A contestant begins by standing at location (0, 0). The contestant collects the money where he or she stands and then jumps either horizontally or vertically to another square. That square must be within the jumping capability of the contestant (say, k locations) and must have more pennies than those that were on the current square. Given n, k, and the number of pennies at each grid location, compute the maximum number of pennies that the contestant can pick up before being unable to move. Input The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. • a line containing two integers between 1 and 100: n and k • n lines, each with n numbers: the first line contains the number of pennies at loca- tions (0,0),(0,1),...,(0,n − 1); the next line contains the number of pennies at locations (1,0),(1,1),...,(1,n−1), and so on. Output For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. • a single integer giving the number of pennies collected Sample Input 1 31 125 10 11 6 12 12 7 Sample Output 37