Chef Restores a Matrix

All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef defines a nondecreasing matrix as a matrix that satisfies the following rules:
 For each row of the matrix, the elements of this row form a nondecreasing sequence.
 For each column of the matrix, the elements of this column form a nondecreasing sequence.
Chef has a matrix A with size N × M. Each element of this matrix is either unknown (denoted by 1) or a positive integer.
Chef would like to replace each unknown element of this matrix by a positive integer in such a way that the resulting matrix is nondecreasing. Find one possible resulting matrix or determine that it's impossible.
Input
 The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
 The first line of each test case contains two spaceseparated integers N and M.
 N lines follow. For each valid i, the ith of these lines contains M spaceseparated integers A_{i1}, A_{i2}, ..., A_{iM} denoting the elements of the ith row of matrix A.
Output
 For each test case, if there is no way to obtain a nondecreasing matrix, print a single line containing the integer 1.
 Otherwise, print N lines describing the matrix obtained by replacing all unknown elements.
 For each valid i, the ith of these lines should contain M spaceseparated integers denoting the elements of the ith row of this matrix. Each of these elements should lie between 1 and 2,000,000,000 inclusive.
Constraints
 1 ≤ T ≤ 100
 1 ≤ N, M ≤ 100
 1 ≤ A_{ij} ≤ 10^{9} or A_{ij} = 1 for each valid i, j
Example
Input: 2 4 4 1 2 2 3 1 1 7 1 6 1 1 1 1 1 1 1 2 3 1 4 1 1 1 3 Output: 1 2 2 3 1 7 7 100 6 10 20 101 7 11 21 20000 1
Author:  kefaa 
Editorial  https://discuss.codechef.com/problems/CO92MATR 
Tags  cook92, easy, implementation, kefaa 
Date Added:  15032018 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 