#include <bits/stdc++.h>
using namespace std;
int t, n, m;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        int tmp;
        scanf("%d", &tmp);
        if ((i + j + tmp) % 2) tmp++;
        printf("%d%c", tmp, " \n"[j == m - 1]);
      }
  }
}
