Fishing

You are a captain of a large fishing ship and you are on a fishing mission in the ocean. The ocean can be modeled by a grid of R rows and C columns. Each cell in the grid can be identified by a pair (r, c) which denotes the row and the column of the cell. In the cell (a, b), there are D[a][b] units of fish. Obviously, we want to fish as many fishes as possible. However, overfishing is bad for the environment. This ocean has a rule to prevent overfishing. The rules state that for every cell that you fish, you have to nourish at least two other cells. To nourish a cell is to simply provide food for the fish in the cell. Additionally, there are two more rules. First, if the latest cell that we fish is at cell (a, b), the next cell that we fish must be at cell (p, q) where p > a and q > b. Second, if the latest cell that we nourished is at cell (a, b) the next cell that we nourish must be at cell (p, q) where p > a and q > b. These rules force us to not overfishing at particular cell and to distribute nourishing. Your task is to calculate maximum possible profit from this fishing. Assuming that the cost to nourish one unit of fish is equal to the profit from one unit of fish, the lump sum benefit of the mission is the summation of cells that we fish minus the summation of the cells that we nourish. Finally, you have to start by nourishing at least 2 cells. In the worst case, we can choose to do nothing at all, resulting in zero benefit. Be noted that fishing and nourishing do not change the number of fishes in the cell. When fishing or nourishing in any cell, we have to fish or nourish all the fishes in that cell. The following list of cells are a possible route of our ship: (0,0) → (2,3) → (1,1) → (3,5) → (4, 7) → (4, 7), where the underlined cell is the cell that we fish. Be noted that it is possible to fish at the cell that we just nourish. The only rule for fishing at cell (p,q) is that the previous cell that we fish is at (a,b) where p > a and q > b. The cell that we nourish does not limit the cell that we fish. Similarly, the only rule for nourishing at cell (p, q) is that the previous nourishing cell is at (a, b) where p > a and q > b. The cell that we fish does not limit the cell that we nourish. Input There are multiple test cases. The first line of input contains an integer T (T ≤ 10) that indicates the number of test cases. Then T test cases follow, each uses the following format. • The first line contains two integer R and C (1 ≤ R, C ≤ 100), the number of rows and columns of the grid. • The next R lines describe the number of fishes in the grid. Each line describes one row of the grid, starting from row 0 to row R − 1. There are C integers in each lines, each describing the value of the cell in that particular row, starting from column 0 to column C − 1. The number of fishes in each cell is non-negative integer not exceeding 1,000. Output For each test case, display one line of output containing the maximum possible benefit that we can get. Sample Input 2 44 1114

2/2 1311 1121 1111 35 11111 11111 11111 Sample Output 2 0