#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2)) * (POW(B, P / 2));
}
long long int Bigmod(long long int base, long long int power,
                     long long int mod) {
  if (power == 0) return 1 % mod;
  if (power == 1) return base % mod;
  long long int x = Bigmod(base, power / 2, mod);
  x = (x * x) % mod;
  if (power % 2) {
    x = (x * (base % mod)) % mod;
  }
  return x;
}
long long int Mulmod(long long int base, long long int power,
                     long long int mod) {
  if (power == 0) return 0;
  if (power == 1) return base % mod;
  long long int x = Mulmod(base, power / 2, mod);
  x = (x + x) % mod;
  if (power % 2) {
    x = (x + (base % mod)) % mod;
  }
  return x;
}
long long int BigMulmod(long long int base, long long int power,
                        long long int mod) {
  if (power == 0) return 1 % mod;
  if (power == 1) return base % mod;
  long long int x = BigMulmod(base, power / 2, mod);
  x = Mulmod(x, x, mod);
  if (power % 2) {
    x = Mulmod(x, (base % mod), mod);
  }
  return x;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
long long int ModInverse(long long int number, long long int mod) {
  return Bigmod(number, mod - 2, mod);
}
bool isConso(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
bool isPrime(long long int val) {
  if (val == 2) return true;
  if (val % 2 == 0 || val == 1) return false;
  long long int sqrt_N = (long long int)((double)sqrt(val));
  for (long long int i = 3; i <= sqrt_N; i += 2) {
    if (val % i == 0) return false;
  }
  return true;
}
template <class T>
string convert(T _input) {
  stringstream blah;
  blah << _input;
  return blah.str();
}
int distchar(char a, char b) {
  int x = ((a - b) + 26) % 26;
  int y = ((b - a) + 26) % 26;
  return min(x, y);
}
bool cmp(pair<long long int, long long int> a,
         pair<long long int, long long int> b) {
  return a > b;
}
unsigned long long int Set(unsigned long long int n, int pos) {
  return n = n | (1 << pos);
}
unsigned long long int Unset(unsigned long long int n, int pos) {
  return n = n & ~(1 << pos);
}
bool check(unsigned long long int n, int pos) { return (bool)(n & (1 << pos)); }
void Solve();
void TEST();
int main() {
  TEST();
  return 0;
}
void TEST() {
  int t = 1, T;
  cin >> T;
  for (__typeof(t) t = 1; t <= T; t++) {
    Solve();
  }
}
void Solve() {
  int n, m;
  cin >> n >> m;
  int ar[n][m], mat[n][m], chs[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ar[i][j];
      mat[i][j] = ar[i][j] % 2;
    }
  }
  int cnt0 = 0, cnt1 = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      chs[i][j] = (i + j) % 2;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] != chs[i][j]) {
        ar[i][j]++;
        cnt++;
      }
    }
  }
  if (cnt == 0) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ar[i][j]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j > 0) cout << ' ';
      cout << ar[i][j];
    }
    cout << '\n';
  }
}
