AlgoUniversity
  • Go Back
Discussion
Chernobyl Disaster :

Author

Ayush Gangwani

Difficulty Level : Easy

Submissions : 246

Asked In : Cogoport

Marks :10

: 2 | : 0

The Chernobyl disaster happened on April $$$26,1986$$$, at the No.$$$4$$$ reactor of the Chernobyl Nuclear Power Plant. In terms of both cost and casualties,it is one of the most devastating nuclear disasters in history.

After the tragedy, scientists retrieved a large number of important documents from the site which contained nuclear power emission data in $$$n$$$ rows and $$$m$$$ columns. This information represented the power emitted by $$$n$$$ nuclear reactors on hourly basis during $$$m$$$ hours. Because these records were handwritten,scientists intend to scan them using optical character scanners to tum numbers into machine encoded text. However, some of the numbers are illegible owing to catastrophic damage.

Scientists opted to reconstruct the missing data by using the rest of the data from that column. Can you help them with a program that detects the minimum number in a column and replaces it with the documents damaged space that is indicated as $$$-1.$$$

Note: If there are all $$$-1$$$ in a column, you can skip that column.

Input

The first line of input contains an integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of testcases. The description of $$$t$$$ testcases follows.

The first line of each testcase contains two space separated integers $$$n$$$ and $$$m$$$ $$$(1 \le n,m \le 10^5)$$$ — the dimensions of the matrix.

The next $$$n$$$ lines contain $$$m$$$ integers each denoting the matrix. Each integer will be in the range $$$[-1,10^9]$$$.

It is guaranteed that the sum of $$$n \cdot m$$$ over all testcases does not exceed $$$10^6$$$.

Output

For each testcase, print the matrix after replacing the missing data as explained in the problem statement.

Example

Input
1
4 4
2 4 6 -1
-1 4 5 6
7 5 8 3
4 3 6 7
Output
2 4 6 3
2 4 5 6
7 5 8 3
4 3 6 7

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.