#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n][m];
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        mp[a[i][j]];
      }
    }
    int no = 0;
    for (auto it : mp) {
      mp[it.first] = no % 2;
      no++;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++)
        if ((i + j) % 2 == mp[a[i][j]]) {
          cout << a[i][j] + 1 << " ";
        } else {
          cout << a[i][j] << " ";
        }
      cout << endl;
    }
  }
}
