#include <bits/stdc++.h>
using namespace std;
const int Max_N = 105;
int Cases, N, M;
int A[Max_N][Max_N], B[Max_N][Max_N];
pair<int, pair<int, int> > P[Max_N * Max_N];
void generate() {
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      P[(i - 1) * M + j] = make_pair(A[i][j], make_pair(i, j));
  sort(P + 1, P + 1 + N * M);
  for (int l, d = 0, r = N * M; r >= 1; r = l - 1, d = d ^ 1) {
    l = r;
    while (l > 1 && P[l - 1].first == P[r].first) --l;
    for (int i = l; i <= r; i++) {
      int x = P[i].second.first, y = P[i].second.second;
      if (((x + y) & 1) == d)
        B[x][y] = A[x][y] + 1;
      else
        B[x][y] = A[x][y];
    }
  }
}
int main() {
  scanf("%d", &Cases);
  while (Cases--) {
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= M; j++) scanf("%d", &A[i][j]);
    generate();
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= M; j++) printf("%d ", B[i][j]);
      puts("");
    }
  }
  return 0;
}
