#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
int n, m, t;
int a[150][150];
map<int, int> mp;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  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];
        if ((i + j) % 2 == 0 && a[i][j] % 2 == 1) {
          a[i][j]++;
        }
        if ((i + j) % 2 == 1 && 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 << endl;
    }
  }
  return 0;
}
