#include <bits/stdc++.h>
using namespace std;
int a[105][105], b[105][105];
int main() {
  int t, n, m;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
    int tmp;
    for (int i = 0; i < n; i++) {
      if (i % 2)
        tmp = 1;
      else
        tmp = 0;
      for (int j = 0; j < m; j++) {
        b[i][j] = tmp % 2;
        tmp++;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] % 2 != b[i][j]) a[i][j]++;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) printf("%d ", a[i][j]);
      printf("\n");
    }
  }
  return 0;
}
