Given a Matrix A[][] of N x M elements. Your task is to make Zeroes, that means in whole Matrix when you find a zero, convert its upper, lower, left, and right value to zero and make that element the sum of the upper, lower, left and right value. Do the following tasks according to the initial Matrix.

**For Example:**

A[][]={{1,2,3,4},

{5,6,0,7},

{8,9,4,6},

{8,4,5,2}};

Output Array should look like:

A[][]={{1,2,0,4},

{5,0,20,0},

{8,9,0,6},

{8,4,5,2}};

**Input:**

The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines.

First line of each test case consist of two space separated integers N and M, denoting the number of element in a row and column respectively.

Second line of each test case consists of N*M space separated integers denoting the elements in the matrix in row major order.

**Output:**

It should be single line output, Print the respective output in the respective line.

**Constraints:**

1<=T<=20

1<=N,M<=10

**Example:
Input:**

1

4 4

1 2 3 4 5 6 0 7 8 9 4 6 8 4 5 2

**Output:**

1 2 0 4 5 0 20 0 8 9 0 6 8 4 5 2

Author: saksham seth

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.

geetyadav | 82 |

hari32147 | 76 |

AdityaRaj9 | 75 |

yashrana1 | 74 |

giavytrinh98 | 64 |

abducodes | 839 |

harshtyagi36 | 417 |

vamsikrishna55 | 323 |

sandipbhaumik | 321 |

Akhil varma | 314 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.