JIXMPII5JUhKW00#%[+

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Statement

You are given a matrix of size n×m n \times m , where the rows are numbered from 1 1 to n n from top to bottom, and the columns are numbered from 1 1 to m m from left to right. The element at the intersection of the i i -th row and the j j -th column is denoted by aij a_{ij} .

Consider the algorithm for stabilizing matrix a a :

  1. Find the cell (i,j) (i, j) such that its value is strictly greater than the values of all its neighboring cells. If there is no such cell, terminate the algorithm. If there are multiple such cells, choose the cell with the smallest value of i i , and if there are still multiple cells, choose the one with the smallest value of j j .
  2. Set aij=aij1 a_{ij} = a_{ij} - 1 .
  3. Go to step 1 1 .

In this problem, cells (a,b) (a, b) and (c,d) (c, d) are considered neighbors if they share a common side, i.e., ac+bd=1 |a - c| + |b - d| = 1 .

Your task is to output the matrix a a after the stabilization algorithm has been executed. It can be shown that this algorithm cannot run for an infinite number of iterations.

Format

Input

Each test consists of multiple sets of input data. The first line contains a single integer t t ( 1t104 1 \leq t \leq 10^4 ) — the number of sets of input data. This is followed by their description.

The first line of each set of input data contains two integers n n and m m ( 1n,m100,nm>1 1 \leq n, m \leq 100, n \cdot m > 1 ) — the number of rows and columns of matrix a a .

The next n n lines describe the corresponding rows of the matrix. The i i -th line contains m m integers ai1,ai2,,aim a_{i1}, a_{i2}, \ldots, a_{im} ( 1aij109 1 \leq a_{ij} \leq 10^9 ).

It is guaranteed that the sum of nm n \cdot m over all sets of input data does not exceed 2105 2 \cdot 10^5 .

Output

For each set of input data, output n n lines with m m numbers in each line — the values of the cells of matrix a a after the stabilization algorithm.

Sample

6
1 2
3 1
2 1
1
1
2 2
1 2
3 4
2 3
7 4 5
1 8 10
5 4
92 74 31 74
74 92 17 7
31 17 92 3
74 7 3 92
7 31 1 1
3 3
1000000000 1 1000000000
1 1000000000 1
1000000000 1 1000000000
1 1 
1 
1 
1 2 
3 3 
4 4 5 
1 8 8 
74 74 31 31 
74 74 17 7 
31 17 17 3 
31 7 3 3 
7 7 1 1 
1 1 1 
1 1 1 
1 1 1

ShanghaiTech ACM 炸鱼杯

未参加
状态
已结束
规则
OI
题目
46
开始于
2024-12-10 23:00
结束于
2024-12-15 13:00
持续时间
110 小时
主持人
参赛人数
112