#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long a[n + 3][m + 4];
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        if (i % 2 != 0) {
          if (j % 2 != 0 && a[i][j] % 2 == 0) {
            a[i][j]++;
          } else if (j % 2 == 0 && a[i][j] % 2 != 0) {
            a[i][j]++;
          }
        } else {
          if (j % 2 != 0 && a[i][j] % 2 != 0) {
            a[i][j]++;
          } else if (j % 2 == 0 && a[i][j] % 2 == 0) {
            a[i][j]++;
          }
        }
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        cout << a[i][j] << " ";
      }
      cout << "\n";
    }
  }
  return 0;
}
