#include <bits/stdc++.h>
using namespace std;
int t, m, n;
int a[500][500];
int main() {
  cin >> t;
  while (t--) {
    memset(a, 0, sizeof(a));
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
        if ((i + j) % 2) {
          if (a[i][j] % 2 == 0) a[i][j]++;
        } else {
          if (a[i][j] % 2) a[i][j]++;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cout << a[i][j] << ' ';
      }
      cout << endl;
    }
  }
}
