#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int dir[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
const char C[4] = {'L', 'R', 'D', 'U'};
int n, m, mat[N], V[N], D[N], deg[N], vis[N], S, T, ans;
map<pair<int, int>, int> mp;
int head[N], cur[N], dep[N], ce;
struct edge {
  int to, nxt, cap, flow;
} e[N * 20];
int id(int x, int y) {
  return (x > 0 && y > 0 && x <= n && y <= m) ? (m * (x - 1) + y) : 0;
}
queue<int> q;
void lnk(int a, int b, int c) {
  e[++ce] = (edge){b, head[a], c, 0}, head[a] = ce;
  e[++ce] = (edge){a, head[b], 0, 0}, head[b] = ce;
}
bool bfs() {
  memset(dep, 0, T + 1 << 2);
  memcpy(cur, head, T + 1 << 2);
  while (!q.empty()) q.pop();
  q.push(S), dep[S] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (!dep[v] && e[i].cap > e[i].flow) {
        dep[v] = dep[u] + 1;
        q.push(v);
        if (v == T) return 1;
      }
    }
  }
  return 0;
}
int dfs(int u, int lim) {
  if (u == T) return lim;
  int tag = 0;
  for (int &i = cur[u]; i; i = e[i].nxt)
    if (dep[e[i].to] == dep[u] + 1 && e[i].cap > e[i].flow) {
      int d = dfs(e[i].to, min(lim - tag, e[i].cap - e[i].flow));
      e[i].flow += d, e[i ^ 1].flow -= d, tag += d;
      if (tag == lim) return lim;
    }
  dep[u] = -1;
  return tag;
}
void solve() {
  cin >> n >> m;
  T = n * m, S = ++T, ++T, ce = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> mat[id(i, j)];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      for (int t = 0; t < 4; ++t) {
        int x = i + dir[t][0], y = j + dir[t][1];
        if (!id(x, y)) continue;
        if (mat[id(x, y)] < mat[id(i, j)])
          D[id(i, j)] = t, V[id(i, j)] = mat[id(i, j)] - mat[id(x, y)];
        if (mat[id(x, y)] == mat[id(i, j)] && ((x + y) & 1))
          lnk(id(x, y), id(i, j), 1);
      }
      if ((i + j) & 1) {
        if (!V[id(i, j)])
          --deg[S], ++deg[id(i, j)];
        else
          lnk(S, id(i, j), 1);
      } else {
        if (!V[id(i, j)])
          ++deg[T], --deg[id(i, j)];
        else
          lnk(id(i, j), T, 1);
      }
    }
  S += 2, T += 2, ans = 0;
  for (int i = 1; i <= T - 2; ++i)
    if (deg[i] < 0)
      lnk(i, T, -deg[i]);
    else if (deg[i] > 0)
      lnk(S, i, deg[i]), ans += deg[i];
  lnk(T - 2, S - 2, 1e9);
  while (bfs()) ans -= dfs(S, 1e9);
  if (ans) {
    puts("NO");
    return;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if ((i + j) & 1)
        for (int k = head[id(i, j)]; k; k = e[k].nxt)
          if (e[k].flow > 0 && e[k].to <= n * m) {
            int to = e[k].to, x = (to - 1) / m + 1, y = (to - 1) % m + 1;
            D[id(i, j)] = mp[{x - i, y - j}], D[id(x, y)] = mp[{i - x, j - y}];
            V[id(i, j)] = 1, V[id(x, y)] = mat[id(i, j)] - 1;
          }
  puts("YES");
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) printf("%d ", V[id(i, j)]);
    puts("");
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) printf("%c ", C[D[id(i, j)]]);
    puts("");
  }
  memset(head, 0, T + 1 << 2), memset(deg, 0, T + 1 << 2);
  memset(vis, 0, T + 1 << 2), memset(mat, 0, T + 1 << 2);
  memset(V, 0, T + 1 << 2);
}
int main() {
  mp[{0, -1}] = 0, mp[{0, 1}] = 1, mp[{1, 0}] = 2, mp[{-1, 0}] = 3;
  int Case;
  cin >> Case;
  while (Case--) solve();
  return 0;
}
