#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int n, m;
int32_t main() {
  c_p_c();
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<vector<long long int> > v(n, vector<long long int>(m));
    for (long long int i = 0; i < (long long int)n; i++)
      for (long long int j = 0; j < (long long int)m; j++) cin >> v[i][j];
    for (long long int i = 0; i < (long long int)n; i++) {
      for (long long int j = 0; j < (long long int)m; j++) {
        long long int temp = i + j;
        if (v[i][j] % 2) {
          if (temp % 2 == 0) v[i][j]++;
        } else {
          if (temp % 2) v[i][j]++;
        }
        cout << v[i][j] << " ";
      }
      cout << "\n";
    }
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
