#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const int BUBEN = 550;
const int MOD = 1e9 + 7;
const int BASE = 29;
const int MOD1 = 998244353;
const int BASE1 = 31;
char _getchar_nolock() { return getchar_unlocked(); }
char _putchar_nolock(char i) { return putchar_unlocked(i); }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> arr(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> arr[i][j];
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; j++) {
        if ((i + j) % 2 == 0) {
          arr[i][j] += arr[i][j] % 2;
        } else {
          arr[i][j] += 1 - arr[i][j] % 2;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << arr[i][j] << ' ';
      }
      cout << '\n';
    }
  }
}
