#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  for (int t = 1; t <= tt; t++) {
    int n, m;
    cin >> n >> m;
    int a[n + 2][m + 2];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
        if ((i + j) % 2 != (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;
    }
  }
}
