#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  int count = 1;
  bool alter = true;
  if (m & 1) alter = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (count & 1) {
        if (a[i][j] & 1) a[i][j]++;
      } else {
        if (!(a[i][j] & 1)) a[i][j]++;
      }
      count++;
    }
    if (alter) {
      if ((i + 1) & 1)
        count = 2;
      else
        count = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << a[i][j] << " ";
    cout << "\n";
  }
  return;
}
int main() {
  long long int t = 1;
  scanf("%lld", &t);
  long long int mod = 1000000007;
  while (t--) {
    solve();
  }
  return 0;
}
