#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, t, m;
  long long int ar[101][101];
  long long int br[101][101];
  cin >> t;
  for (long long int i = 1; i <= t; i++) {
    set<long long int> s;
    cin >> n >> m;
    for (long long int i = 0; i <= n - 1; i++) {
      for (long long int j = 0; j < m; j++) {
        cin >> ar[i][j];
        br[i][j] = ar[i][j];
        s.insert(ar[i][j]);
      }
    }
    if (n == 1 && m == 1)
      cout << ar[0][0] << endl;
    else {
      for (long long int i = 0; i <= n - 1; i++) {
        for (long long int j = 0; j < m; j++) {
          if (!(i & 1) && !(j & 1) && (ar[i][j] & 1)) {
            ar[i][j]++;
          }
          if (!(i & 1) && (j & 1) && !(ar[i][j] & 1)) {
            ar[i][j]++;
          }
          if ((i & 1) && (j & 1) && (ar[i][j] & 1)) {
            ar[i][j]++;
          }
          if ((i & 1) && !(j & 1) && !(ar[i][j] & 1)) {
            ar[i][j]++;
          }
        }
      }
      for (long long int i = 0; i <= n - 1; i++) {
        for (long long int j = 0; j < m; j++) {
          cout << ar[i][j] << " ";
        }
        cout << endl;
      }
    }
  }
  return 0;
}
