#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[100][100];
    for (int i = 0; i < n; i++) {
      int k = 0;
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        if (i % 2 == 0) {
          if (k % 2 == 0 && a[i][j] % 2 != 0) {
            a[i][j]++;
          } else if (k % 2 != 0 && a[i][j] % 2 == 0) {
            a[i][j]++;
          }
        } else {
          if (k % 2 == 0 && a[i][j] % 2 == 0) {
            a[i][j]++;
          } else if (k % 2 != 0 && a[i][j] % 2 != 0) {
            a[i][j]++;
          }
        }
        cout << a[i][j] << ' ';
        k++;
      }
      cout << "\n";
    }
  }
}
