#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int T, n, m, a[N][N], b[N][N], mx[4] = {1, -1, 0, 0}, my[4] = {0, 0, 1, -1};
set<pair<int, pair<int, int> > > s;
void _clear() { s.clear(); }
bool inline inside(int x, int y) {
  return x >= 1 && x <= n && y >= 1 && y <= m;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    _clear();
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
    for (int x = 1; x <= n; x++)
      for (int y = 1; y <= m; y++)
        for (int i = 0; i < 4; i++) {
          int nx = x + mx[i];
          int ny = y + my[i];
          if (inside(nx, ny) && a[nx][ny] == a[x][y])
            s.insert({a[x][y], {x, y}});
        }
    s.insert({2e9, {0, 0}});
    bool q = 0;
    while (!s.empty()) {
      pair<int, pair<int, int> > p = *s.begin();
      if (p.first == 2e9) break;
      vector<pair<int, pair<int, int> > > v;
      while (1) {
        pair<int, pair<int, int> > p2 = *s.begin();
        if (p2.first != p.first) break;
        s.erase(p2);
        v.push_back(p2);
      }
      q ^= 1;
      for (auto x : v)
        if ((x.second.first + x.second.second) % 2 == q)
          a[x.second.first][x.second.second]++;
      for (auto x : v)
        if ((x.second.first + x.second.second) % 2 == q) {
          for (int i = 0; i < 4; i++) {
            int nx = x.second.first + mx[i];
            int ny = x.second.second + my[i];
            if (inside(nx, ny) &&
                a[nx][ny] == a[x.second.first][x.second.second])
              s.insert({a[nx][ny], {nx, ny}});
          }
        }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) printf("%d ", a[i][j]);
      printf("\n");
    }
  }
}
