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