#include <bits/stdc++.h>
using namespace std;
inline void swap(int &x, int &y) { x ^= y ^= x ^= y; }
const double pi = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int limit = 5e5;
inline int read() {
  int x = 0;
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 0;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  if (f) return x;
  return 0 - x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const long long mod = 1e9 + 7;
const int N = 100 + 5;
int i, j, k;
int n, m, t;
int a[N][N];
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%d", &a[i][j]);
        if ((i + j) % 2 == a[i][j] % 2) a[i][j]++;
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cout << a[i][j] << " ";
        a[i][j] = 0;
      }
      cout << endl;
    }
  }
  return 0;
}
