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