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.

narahc321 | 170 |

agness | 163 |

lonecoder | 153 |

2016uec1342 | 142 |

HuHu | 140 |

lonecoder | 1088 |

nikhil_sojan | 1082 |

KshatriyaYash | 1066 |

mazumderrohit8 | 928 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4504 |

Quandray | 4444 |

Login to report an issue on this page.