#include <bits/stdc++.h>
using namespace std;
char buffer[2000020], *p1, *p2;
template <class T>
void read(T& x) {
  char ch = ((p1 == p2 &&
              (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
                 ? EOF
                 : *p1++);
  x = 0;
  bool f = 1;
  while (!('0' <= ch && ch <= '9') && ch != '-')
    ch = ((p1 == p2 &&
           (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
              ? EOF
              : *p1++);
  if (ch == '-')
    f = 0,
    ch = ((p1 == p2 &&
           (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
              ? EOF
              : *p1++);
  while ('0' <= ch && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0',
    ch = ((p1 == p2 &&
           (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
              ? EOF
              : *p1++);
  x = (f) ? x : -x;
}
int _num[20];
template <class T>
void write(T x, char sep = '\n') {
  if (!x) {
    putchar('0'), putchar(sep);
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  int c = 0;
  while (x) _num[++c] = x % 10, x /= 10;
  while (c) putchar('0' + _num[c--]);
  putchar(sep);
}
int n, m, a[220][220], lis[220 * 220], cs = 0;
int main() {
  int T;
  read(T);
  while (T--) {
    read(n), read(m);
    for (register int i = 1; i <= n; i++)
      for (register int j = 1; j <= m; j++) read(a[i][j]), lis[++cs] = a[i][j];
    sort(lis + 1, lis + 1 + cs);
    cs = unique(lis + 1, lis + 1 + cs) - lis - 1;
    for (register int i = 1; i <= n; i++)
      for (register int j = 1; j <= m; j++) {
        a[i][j] += ((lower_bound(lis + 1, lis + 1 + cs, a[i][j]) - lis) & 1) ^
                   ((i + j) & 1);
      }
    for (register int i = 1; i <= n; i++) {
      for (register int j = 1; j <= m; j++) write(a[i][j], ' ');
      puts("");
    }
  }
  return 0;
}
