#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  int T, n, m, a;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++)
        cin >> a, cout << a + (a % 2 != (i + j) % 2) << " \n"[j == m];
  }
  return 0;
}
