#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long M = 998244353;
long long pow1(long long a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % M;
    }
    a = (a * a) % M;
    b >>= 1;
  }
  return res % M;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T;
  T = 1;
  cin >> T;
  while (T--) {
    long long n, m;
    cin >> n >> m;
    long long ans[n][m];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        long long num;
        cin >> num;
        if (num % 2 != (i + j) % 2)
          ans[i][j] = num + 1;
        else
          ans[i][j] = num;
        cout << ans[i][j] << " ";
      }
      cout << "\n";
    }
  }
}
