#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int mapp[110][110];
int b[110][110];
int main() {
  int Cas = 1;
  scanf("%d", &Cas);
  while (Cas--) {
    int n, m;
    scanf("%d%d", &n, &m);
    memset(mapp, 0, sizeof(mapp));
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        scanf("%d", &mapp[i][j]);
        int flag = (i + j) % 2;
        if (mapp[i][j] % 2 == flag)
          b[i][j] = mapp[i][j];
        else
          b[i][j] = mapp[i][j] + 1;
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) printf("%d%c", b[i][j], j == m ? '\n' : ' ');
  }
  return 0;
}
