#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
void OFAST() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}
int main() {
  double timing = clock();
  OFAST();
  int tes;
  cin >> tes;
  while (tes--) {
    int n, m, u;
    cin >> n >> m;
    for (int i = (1), _b = (n); i <= _b; ++i) {
      for (int j = (1), _b = (m); j <= _b; ++j) {
        cin >> u;
        if (((i + j) & 1) != (u & 1)) ++u;
        cout << u << ' ';
      }
      cout << endl;
    }
  }
  cerr << "\n\nREAL TIME: " << fixed << setprecision(4)
       << (clock() - timing) / CLOCKS_PER_SEC << endl;
}
