#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
int n, m;
vector<int> a[100010];
int head[100010], v[400010 << 1], nxt[400010 << 1], w[400010 << 1], tot = 0,
                                                                    deg[100010];
int S, T, _S, _T;
int nx[4] = {-1, 1, 0, 0};
int ny[4] = {0, 0, -1, 1};
char opt[4] = {'U', 'D', 'L', 'R'};
inline void add_edge(int s, int e, int t) {
  tot++;
  v[tot] = e;
  w[tot] = t;
  nxt[tot] = head[s];
  head[s] = tot;
  tot++;
  v[tot] = s;
  w[tot] = 0;
  nxt[tot] = head[e];
  head[e] = tot;
}
int to[100010], val[100010];
int id(int i, int j) { return (i - 1) * m + j; }
void output(int t) {
  int i = (t + m - 1) / m, j = t % m;
  if (!j) j = m;
  int h1 = (to[t] + m - 1) / m, h2 = to[t] % m;
  if (!h2) h2 = m;
  for (int k = (0); k <= (3); ++k)
    if (i + nx[k] == h1 && j + ny[k] == h2) {
      putchar(opt[k]);
      break;
    }
  putchar(' ');
}
int cur[100010], edge[400010], len;
int Q[100010], hd, tl, d[100010];
bool Bfs() {
  for (int i = (0); i <= (tl - 1); ++i) d[Q[i]] = -1;
  d[S] = 0;
  hd = tl = 0;
  Q[tl++] = S;
  while (hd < tl) {
    int u = Q[hd];
    hd++;
    for (int i = head[u]; i; i = nxt[i])
      if (w[i] && d[v[i]] < 0) {
        d[v[i]] = d[u] + 1;
        Q[tl++] = v[i];
        if (v[i] == T) return true;
      }
  }
  return false;
}
int find(int u, int flow) {
  if (u == T || !flow) return flow;
  int res = 0, minv;
  for (int &i = head[u]; i; i = nxt[i])
    if (w[i] && d[v[i]] == d[u] + 1 && (minv = find(v[i], min(flow, w[i])))) {
      w[i] -= minv;
      if (i & 1)
        w[i + 1] += minv;
      else
        w[i - 1] += minv;
      res += minv;
      flow -= minv;
      if (!flow) break;
    }
  return res;
}
void init() {
  tot = 0;
  memset(head, 0, sizeof(int) * (T + 1));
  memset(deg, 0, sizeof(int) * (T + 1));
  len = 0;
  memset(to, 0, sizeof(int) * (n * m + 1));
}
inline void rd(int &x) {
  x = 0;
  char ch = getchar();
  int f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int main() {
  int Task;
  rd(Task);
  while (Task--) {
    rd(n);
    rd(m);
    for (int i = (1); i <= (n); ++i) {
      a[i].resize(m + 1);
      for (int j = (1); j <= (m); ++j) rd(a[i][j]);
    }
    init();
    if (n == 1 && m == 1) {
      puts("NO");
      continue;
    }
    _S = n * m + 1;
    _T = n * m + 2;
    for (int i = (1); i <= (n); ++i)
      for (int j = (1); j <= (m); ++j) {
        bool flag = true;
        for (int k = (0); k <= (3); ++k)
          if (i + nx[k] >= 1 && i + nx[k] <= n && j + ny[k] >= 1 &&
              j + ny[k] <= m) {
            if (a[i + nx[k]][j + ny[k]] < a[i][j]) flag = false;
            if (a[i + nx[k]][j + ny[k]] == a[i][j] && ((i + j) & 1)) {
              add_edge(id(i, j), id(i + nx[k], j + ny[k]), 1);
              edge[++len] = tot - 1;
            }
          }
        if (flag) {
          if ((i + j) & 1) {
            deg[_S]++;
            deg[id(i, j)]--;
          } else {
            deg[id(i, j)]++;
            deg[_T]--;
          }
        } else {
          if ((i + j) & 1)
            add_edge(_S, id(i, j), 1);
          else
            add_edge(id(i, j), _T, 1);
        }
      }
    add_edge(_T, _S, n * m);
    S = _T + 1;
    T = _T + 2;
    int sum = 0;
    for (int i = (1); i <= (_T); ++i)
      if (deg[i] > 0)
        add_edge(i, T, deg[i]), sum += deg[i];
      else if (deg[i] < 0)
        add_edge(S, i, -deg[i]);
    memset(d, -1, sizeof(int) * (T + 1));
    memcpy(cur, head, sizeof(int) * (T + 1));
    int ans = 0;
    while (Bfs()) {
      ans += find(S, inf);
      memcpy(head, cur, sizeof(int) * (T + 1));
    }
    if (ans < sum) {
      puts("NO");
      continue;
    } else {
      puts("YES");
      for (int i = (1); i <= (len); ++i)
        if (w[edge[i]] == 0) {
          int t = edge[i];
          to[v[t]] = v[t + 1];
          to[v[t + 1]] = v[t];
          int x = (v[t] + m - 1) / m, y = v[t] % m;
          if (!y) y = m;
          val[v[t]] = a[x][y] / 2;
          val[v[t + 1]] = (a[x][y] + 1) / 2;
        }
      for (int i = (1); i <= (n); ++i)
        for (int j = (1); j <= (m); ++j)
          if (!to[id(i, j)]) {
            int t = id(i, j);
            for (int k = (0); k <= (3); ++k)
              if (i + nx[k] >= 1 && i + nx[k] <= n && j + ny[k] >= 1 &&
                  j + ny[k] <= m && a[i + nx[k]][j + ny[k]] < a[i][j]) {
                to[t] = id(i + nx[k], j + ny[k]);
                val[t] = a[i][j] - a[i + nx[k]][j + ny[k]];
                break;
              }
          }
      for (int i = (1); i <= (n); ++i) {
        for (int j = (1); j <= (m); ++j) printf("%d ", val[id(i, j)]);
        puts("");
      }
      for (int i = (1); i <= (n); ++i) {
        for (int j = (1); j <= (m); ++j) output(id(i, j));
        puts("");
      }
    }
  }
  return 0;
}
