#include <bits/stdc++.h>
using namespace std;
int Tes, n, m, p, k, fx[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}, a[200010],
                     W[200010], U[1600010], V[1600010], sth = 0;
char op[] = {'R', 'L', 'D', 'U'}, s[200010], Ud[1600010], Vd[1600010];
int head[200010], cur[200010], o, dep[200010], S, T, SS, TT, cnt, tmp, flow;
struct edge {
  int to, link, w;
} e[1600010];
void add_edge(int u, int v, int w) {
  if (!w) return;
  e[++o].to = v, e[o].link = head[u], head[u] = o, e[o].w = w;
  e[++o].to = u, e[o].link = head[v], head[v] = o, e[o].w = 0;
  U[o] = SS;
}
void add_edge(int u, int v, int L, int R) {
  add_edge(SS, v, L), add_edge(u, TT, L), add_edge(u, v, R - L), tmp += L;
}
bool bfs() {
  memset(dep, 0, 4 * (cnt + 1));
  queue<int> q;
  dep[SS] = 1, q.push(SS);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].link) {
      sth++;
      if (dep[e[i].to] || !e[i].w) continue;
      dep[e[i].to] = dep[u] + 1;
      q.push(e[i].to);
    }
  }
  return dep[TT];
}
int dfs(int u, int in) {
  if (u == TT) return in;
  int out = 0;
  for (int &i = cur[u]; i; i = e[i].link) {
    sth++;
    if (dep[e[i].to] != dep[u] + 1 || !e[i].w) continue;
    int res = dfs(e[i].to, min(in, e[i].w));
    in -= res, out += res;
    e[i].w -= res, e[i ^ 1].w += res;
    if (!in) break;
  }
  return out;
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[(i - 1) * m + j]);
  o = 1, tmp = flow = 0;
  cnt = (n - 1) * m + m, S = ++cnt, T = ++cnt, SS = ++cnt, TT = ++cnt;
  for (int i = 1; i <= cnt; i++) head[i] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int L = 1;
      for (int k = 0; k < 4; k++) {
        int xx = i + fx[k][0], yy = j + fx[k][1];
        if (xx <= n && xx >= 1 && yy <= m && yy >= 1) {
          if (a[(xx - 1) * m + yy] < a[(i - 1) * m + j])
            L = 0, s[(i - 1) * m + j] = op[k],
            W[(i - 1) * m + j] = a[(i - 1) * m + j] - a[(xx - 1) * m + yy];
          if (a[(xx - 1) * m + yy] == a[(i - 1) * m + j] && ((i ^ j) & 1)) {
            add_edge((i - 1) * m + j, (xx - 1) * m + yy, 1);
            U[o] = (i - 1) * m + j, V[o] = (xx - 1) * m + yy;
            Ud[o] = op[k], Vd[o] = op[k ^ 1];
          }
        }
      }
      if ((i ^ j) & 1)
        add_edge(S, (i - 1) * m + j, L, 1);
      else
        add_edge((i - 1) * m + j, T, L, 1);
    }
  add_edge(T, S, 2e9);
  while (bfs()) memcpy(cur, head, 4 * (cnt + 1)), flow += dfs(SS, 2e9);
  if (tmp != flow) return puts("NO"), void();
  for (int i = 3; i <= o; i += 2) {
    if (e[i].w && U[i] != SS) {
      s[U[i]] = Ud[i], s[V[i]] = Vd[i];
      W[U[i]] = 1, W[V[i]] = a[U[i]] - 1;
    }
  }
  cerr << sth << "\n";
  puts("YES");
  for (int i = 1; i <= n; i++, puts(""))
    for (int j = 1; j <= m; j++) printf("%d ", W[(i - 1) * m + j]);
  for (int i = 1; i <= n; i++, puts(""))
    for (int j = 1; j <= m; j++) printf("%c ", s[(i - 1) * m + j]);
}
int main() {
  scanf("%d", &Tes);
  while (Tes--) solve();
}
