## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## X-Sum Codeforces Solution | Codeforces Problem Solution 2022

D. X-Sum
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $a$ with $n$ rows and $m$ columns with each cell having a non-negative integer written on it.

Timur's challenge is to place a bishop on the board such that the sum of all cells attacked by the bishop is maximal. The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked. Help him find the maximal sum he can get.

Input

The first line of the input contains a single integer $t$ ($1\le t\le 1000$) — the number of test cases. The description of test cases follows.

Most Similar Words Codeforces Solution

The first line of each test case contains the integers $n$ and $m$ ($1\le n\le 200$$1\le m\le 200$).

The following $n$ lines contain $m$ integers each, the $j$-th element of the $i$-th line ${a}_{ij}$ is the number written in the $j$-th cell of the $i$-th row $\left(0\le {a}_{ij}\le {10}^{6}\right)$

It is guaranteed that the sum of $n\cdot m$ over all test cases does not exceed $4\cdot {10}^{4}$.

Output

For each test case output a single integer, the maximum sum over all possible placements of the bishop.