#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = N * 10;
const int inf = INT_MAX / 3 * 2;
int n, m, cnt, ss, tt, sum, ut[M], vt[M];
char ud[M], vd[M];
namespace FlowGraph {
int head[N], v[M], nxt[M], ptr, t;
int w[M];
inline void padd_edge(int uu, int vv, int ww) {
  v[ptr] = vv;
  w[ptr] = ww;
  nxt[ptr] = head[uu];
  head[uu] = ptr++;
}
int dis[N], cur[N];
bool bfs(int s, int t) {
  memset(dis, -1, sizeof(int) * (cnt + 1));
  queue<int> q;
  q.push(s);
  dis[s] = 1;
  while (!q.empty()) {
    int nd = q.front();
    q.pop();
    for (int i = head[nd]; i != -1; i = nxt[i])
      if (w[i] && dis[v[i]] == -1) {
        dis[v[i]] = dis[nd] + 1;
        q.push(v[i]);
      }
  }
  return dis[t] != -1;
}
int dfs(int pos, int flow) {
  if (pos == t) return flow;
  int tmp = flow;
  for (int &i = cur[pos]; i != -1; i = nxt[i])
    if (w[i] && dis[v[i]] == dis[pos] + 1) {
      int fl = dfs(v[i], min(flow, w[i]));
      w[i] -= fl;
      w[i ^ 1] += fl;
      flow -= fl;
      if (!flow) break;
    }
  return tmp - flow;
}
void init() {
  ptr = 0;
  memset(head, -1, sizeof(int) * (cnt + 1));
}
inline void add_edge(int uu, int vv, int ww) {
  if (ww) padd_edge(uu, vv, ww), padd_edge(vv, uu, 0), ut[ptr - 1] = ss;
}
inline void add_edge(int uu, int vv, int l, int r) {
  add_edge(ss, vv, l);
  add_edge(uu, tt, l);
  add_edge(uu, vv, r - l);
  sum += l;
}
int dinic(int ss, int tt) {
  t = tt;
  int ret = 0;
  while (bfs(ss, tt))
    memcpy(cur, head, sizeof(int) * (cnt + 1)), ret += dfs(ss, inf);
  return ret;
}
};  // namespace FlowGraph
inline int id(int x, int y) { return (x - 1) * m + y; }
int a[N];
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
char op[] = {'R', 'L', 'D', 'U'};
char s[N];
int w[N];
void _main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[id(i, j)];
  cnt = id(n, m);
  int S = ++cnt, T = ++cnt;
  ss = ++cnt, tt = ++cnt;
  FlowGraph::init();
  sum = 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 + d[k][0], yy = j + d[k][1];
        if (xx <= n && xx && yy <= m && yy) {
          if (a[id(xx, yy)] < a[id(i, j)])
            l = 0, s[id(i, j)] = op[k],
            w[id(i, j)] = a[id(i, j)] - a[id(xx, yy)];
          if (a[id(xx, yy)] == a[id(i, j)] && ((i ^ j) & 1)) {
            FlowGraph::add_edge(id(i, j), id(xx, yy), 1);
            ut[FlowGraph::ptr - 1] = id(i, j);
            vt[FlowGraph::ptr - 1] = id(xx, yy);
            ud[FlowGraph::ptr - 1] = op[k];
            vd[FlowGraph::ptr - 1] = op[k ^ 1];
          }
        }
      }
      if ((i ^ j) & 1)
        FlowGraph::add_edge(S, id(i, j), l, 1);
      else
        FlowGraph::add_edge(id(i, j), T, l, 1);
    }
  FlowGraph::add_edge(T, S, inf);
  int fl = FlowGraph::dinic(ss, tt);
  if (sum != fl) {
    cout << "NO" << endl;
    return;
  }
  for (int i = 1; i < FlowGraph::ptr; i += 2) {
    if (FlowGraph::w[i] && ut[i] != ss)
      s[ut[i]] = ud[i], s[vt[i]] = vd[i], w[ut[i]] = 1, w[vt[i]] = a[ut[i]] - 1;
  }
  cout << "YES" << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << w[id(i, j)] << ' ';
    cout << endl;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << s[id(i, j)] << ' ';
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) _main();
  return 0;
}
