#include <bits/stdc++.h>
using namespace std;
char _buf[100000], *_op(_buf), *_ed(_buf);
inline int getint() {
  int _s = 0, _f = 1;
  char _ch = (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),
                             _op == _ed)
                  ? EOF
                  : *_op++);
  while (!('0' <= _ch && _ch <= '9'))
    (_ch == '-') && (_f = -1),
        _ch =
            (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),
                            _op == _ed)
                 ? EOF
                 : *_op++);
  while (('0' <= _ch && _ch <= '9'))
    _s = _s * 10 + _ch - 48,
    _ch = (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),
                          _op == _ed)
               ? EOF
               : *_op++);
  return _s * _f;
}
const int N = 5e5 + 2, INF = 0x3f3f3f3f;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const char st[10] = "RDLU";
int T, n, m, tot, now;
int lk[N], kl[N], dfn[N];
vector<int> a[N], e[N], b[N], c[N];
inline int id(int x, int y) { return (x - 1) * m + y; }
inline void input() {
  n = getint(), m = getint(), tot = n * m;
  for (int i = 1; i <= n; i++) b[i].clear(), c[i].clear(), a[i].clear();
  for (int i = 1; i <= n; i++)
    a[i].resize(m + 1), b[i].resize(m + 1), c[i].resize(m + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = getint();
}
inline int valid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
inline void init(int tx = 0, int ty = 0) {
  now = 0;
  for (int i = 1; i <= tot * 3; i++) e[i].clear(), dfn[i] = lk[i] = kl[i] = 0;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++)
      for (int i = 0; i <= 3; i++)
        if (valid(tx = x + dx[i], ty = y + dy[i]) && a[x][y] == a[tx][ty]) {
          e[id(x, y)].push_back(id(tx, ty));
        }
}
inline int dfs0(int u) {
  if (dfn[u] == now) return 0;
  dfn[u] = now;
  for (int v : e[u])
    if (!kl[v] || dfs0(kl[v])) return kl[v] = u, lk[u] = v, 1;
  return 0;
}
inline int dfs1(int u) {
  if (dfn[u] == now) return 0;
  dfn[u] = now;
  for (int v : e[u])
    if (!lk[v] || dfs1(lk[v])) return lk[v] = u, kl[u] = v, 1;
  return 0;
}
inline void work() {
  int tx, ty, cnt, u, v;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      cnt = 0, u = id(x, y);
      for (int i = 0; i <= 3; i++)
        if (valid(tx = x + dx[i], ty = y + dy[i])) cnt += a[tx][ty] < a[x][y];
      if (cnt) {
        if (x + y & 1)
          e[u].push_back(u + tot), e[u + tot].push_back(u);
        else
          e[u].push_back(u + tot + tot), e[u + tot + tot].push_back(u);
      }
    }
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      cnt = 0, u = id(x, y);
      for (int i = 0; i <= 3; i++)
        if (valid(tx = x + dx[i], ty = y + dy[i])) cnt += a[tx][ty] < a[x][y];
      if (!cnt) {
        if (x + y & 1) {
          if (!lk[u] && ++now && !dfs0(u)) return void(cout << "NO\n");
        } else {
          if (!kl[u] && ++now && !dfs1(u)) return void(cout << "NO\n");
        }
      }
    }
  cout << "YES\n";
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      u = id(x, y);
      if (x + y & 1) {
        if (lk[u] && lk[u] <= tot) {
          for (int i = 0; i <= 3; i++)
            if (valid(tx = x + dx[i], ty = y + dy[i]) && id(tx, ty) == lk[u]) {
              if (!b[tx][ty])
                b[x][y] = 1;
              else
                b[x][y] = a[x][y] - 1;
              c[x][y] = i;
              break;
            }
          continue;
        }
      } else {
        if (kl[u] && kl[u] <= tot) {
          for (int i = 0; i <= 3; i++)
            if (valid(tx = x + dx[i], ty = y + dy[i]) && id(tx, ty) == kl[u]) {
              if (!b[tx][ty])
                b[x][y] = 1;
              else
                b[x][y] = a[x][y] - 1;
              c[x][y] = i;
              break;
            }
          continue;
        }
      }
      for (int i = 0; i <= 3; i++)
        if (valid(tx = x + dx[i], ty = y + dy[i]) && a[tx][ty] < a[x][y]) {
          b[x][y] = a[x][y] - a[tx][ty], c[x][y] = i;
          break;
        }
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cout << b[i][j] << " \n"[j == m];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cout << st[c[i][j]] << " \n"[j == m];
}
int main() {
  for (scanf("%d", &T); T--;) {
    input();
    init();
    work();
  }
  return 0;
}
