Jack is a treasure hunter who loves to explore ancient ruins. One day, he stumbled upon a hidden chamber that contained a large grid of squares. Each square had a number of diamonds embedded in it. Jack noticed a sign that said: "To claim the treasure, you must find a path from the top left corner to the bottom right corner of the grid, and collect as many diamonds as possible along the way. But beware, once you enter the grid, you can only move right or down."
Jack was intrigued by the challenge and decided to give it a try. He was about to enter the grid when he spotted a golden lamp lying near the entrance. He picked up the lamp and rubbed it, hoping for some extra luck. To his surprise, a genie popped out of the lamp and greeted him. "Hello, Master. I am the genie of the grid. I will grant you one wish, but it must be related to the grid. What do you wish for?"
Jack thought for a moment and realized that he could use the genie's help to improve his path. He asked the genie to allow him to move to the left once, so that he could collect more diamonds. The genie nodded and said: "Your wish is granted. You can now move to the left once, but only once. Use it wisely."
Jack thanked the genie and entered the grid. What is the maximum number of diamonds he can collect?
The first line of input contains the number of test cases $$$Z$$$ ($$$1 \leq Z \leq 500\ 000$$$). The descriptions of the test cases follow.
The first line of a test case contains two numbers $$$n,m$$$ ($$$1 \leq n,m \leq 3\,000$$$) – the dimensions of the grid.
The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th number in the $$$i$$$-th line $$$d_{i,j}$$$ is the number of diamonds in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \leq d_{i,j} \leq 10^6$$$).
The sum $$$\sum n\cdot m$$$ over all test cases will not exceed $$$9\,000\,000$$$.
For each test case, print in a single line the maximum number of diamonds that Jack can collect. Note that Jack does not have to move left, and that he cannot collect diamonds from one square twice.
2 3 2 1 1 1 1 1 1 2 2 1 2 0 4
6 7
In the first test case, one of the optimal paths is RDLDR. In the second test case, both RD and RLRD paths are optimal.