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.

ShubhamJain18 | 205 |

makeitdonesolo | 140 |

lost_found | 124 |

maggiiiii | 118 |

SahatPrasad1 | 108 |

Bishnu Dev Panda | 777 |

okayboss | 551 |

ShubhamJain18 | 516 |

yk12 | 514 |

makeitdonesolo | 480 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.