Given a 2D matrix, the task is to find maximum sum of a hour glass.

```
An hour glass is made of 7 cells
in following form.
A B C
D
E F G
```

Examples:

```
Input : 1 1 1 0 0
0 1 0 0 0
1 1 3 0 0
0 0 0 2 0
0 0 0 0 4
Output : 9
Below is the hour glass with
maximum sum:
3 0 0
2
0 0 4
```

**Input:**

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two space separated integers N and M denoting the size of the matrix. Then in the next line are N*M values of the matrix (m).

**Output:**

For each test case in a new line print the required output.

**Constraints:**

1<=T<=100

1<=N,M<=20

1<=m[][]<1000

**Example:
Input:**

2

1 2

1 2

3 3

1 1 1 1 1 1 1 1 1

**Output:**

-1

7

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

the_coder95 | 465 |

thanuvinu94 | 388 |

adityasuman2025 | 305 |

Senbonzakura_Kageyoshi | 297 |

PrakharBansal1 | 274 |

the_coder95 | 1691 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 1064 |

samay_kam_hai | 724 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.