#include <bits/stdc++.h>
using namespace std;
template <typename flow_t = long long>
struct PushRelabel {
  struct Edge {
    int to, rev;
    flow_t f, c;
  };
  vector<vector<Edge> > g;
  vector<flow_t> ec;
  vector<Edge *> cur;
  vector<vector<int> > hs;
  vector<int> H;
  PushRelabel() {}
  PushRelabel(int n) : g(n), ec(n), cur(n), hs(2 * n), H(n) {}
  void add_edge(int s, int t, flow_t cap, flow_t rcap = 0) {
    if (s == t) return;
    Edge a = {t, (int)g[t].size(), 0, cap};
    Edge b = {s, (int)g[s].size(), 0, rcap};
    g[s].push_back(a);
    g[t].push_back(b);
  }
  void add_flow(Edge &e, flow_t f) {
    Edge &back = g[e.to][e.rev];
    if (!ec[e.to] && f) hs[H[e.to]].push_back(e.to);
    e.f += f;
    e.c -= f;
    ec[e.to] += f;
    back.f -= f;
    back.c += f;
    ec[back.to] -= f;
  }
  flow_t max_flow(int s, int t) {
    int v = g.size();
    H[s] = v;
    ec[t] = 1;
    vector<int> co(2 * v);
    co[0] = v - 1;
    for (int i = 0; i < v; ++i) cur[i] = g[i].data();
    for (auto &e : g[s]) add_flow(e, e.c);
    if (hs[0].size())
      for (int hi = 0; hi >= 0;) {
        int u = hs[hi].back();
        hs[hi].pop_back();
        while (ec[u] > 0)
          if (cur[u] == g[u].data() + g[u].size()) {
            H[u] = 1e9;
            for (auto &e : g[u])
              if (e.c && H[u] > H[e.to] + 1) H[u] = H[e.to] + 1, cur[u] = &e;
            if (++co[H[u]], !--co[hi] && hi < v)
              for (int i = 0; i < v; ++i)
                if (hi < H[i] && H[i] < v) {
                  --co[H[i]];
                  H[i] = v + 1;
                }
            hi = H[u];
          } else if (cur[u]->c && H[u] == H[cur[u]->to] + 1)
            add_flow(*cur[u], min(ec[u], cur[u]->c));
          else
            ++cur[u];
        while (hi >= 0 && hs[hi].empty()) --hi;
      }
    return -ec[s];
  }
};
struct lower_f {
  PushRelabel<> A;
  int success, S_, T_;
  int tot;
  void init(int n) {
    A = PushRelabel<>(n + 3);
    success = 1;
    tot = 0;
    S_ = n + 1;
    T_ = n + 2;
  }
  void insert(int a, int b, int lc, int hc) {
    if (hc < lc) success = 0;
    A.add_edge(S_, b, lc);
    A.add_edge(a, T_, lc);
    A.add_edge(a, b, hc - lc);
    tot += lc;
  }
  int MaxFlow(int S, int T) {
    if (!success) return -1;
    A.add_edge(T, S, (1 << 30));
    int q = A.max_flow(S_, T_);
    return (q == tot ? 1 : -1);
  }
} P;
int n, m, h;
vector<int> a[100201], id[100201], b[100201];
pair<int, int> rev[100201];
vector<int> a1[100201];
vector<char> a2[100201];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
char dir[4] = {'L', 'U', 'R', 'D'};
void solve() {
  scanf("%d%d", &n, &m);
  h = 0;
  for (int i = 1; i <= n; i++) {
    a1[i].clear();
    a2[i].clear();
    a[i].clear();
    b[i].clear();
    id[i].clear();
    for (int j = 1; j <= m; j++) {
      int d;
      scanf("%d", &d);
      a[i].push_back(d);
      b[i].push_back(0);
      a1[i].push_back(0);
      a2[i].push_back('A');
      id[i].push_back(++h);
      rev[h] = make_pair(i, j - 1);
    }
  }
  P.init(h + 2);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < m; j++) {
      int myid = id[i][j];
      int par = (i + j) % 2;
      for (int k = 0; k <= 3; k++) {
        int cx = i + dx[k];
        int cy = j + dy[k];
        if (cx >= 1 && cx <= n && cy >= 0 && cy < m) {
          int nid = id[cx][cy];
          if (a[cx][cy] == a[i][j]) {
            if (par) {
              P.insert(myid, nid, 0, 1);
            } else {
            }
          }
          if (a[cx][cy] < a[i][j]) {
            b[i][j] = 1;
            a1[i][j] = a[i][j] - a[cx][cy];
            a2[i][j] = dir[k];
          }
        }
      }
      if (par) {
        P.insert(h + 1, myid, 1 - b[i][j], 1);
      } else {
        P.insert(myid, h + 2, 1 - b[i][j], 1);
      }
    }
  int good = P.MaxFlow(h + 1, h + 2);
  if (good == -1) {
    puts("NO");
    return;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < m; j++) {
      int myid = id[i][j];
      int par = (i + j) % 2;
      if (par) {
        for (auto e : P.A.g[myid])
          if (e.f == 1) {
            int nt = e.to;
            if (nt <= h) {
              int cx = rev[nt].first;
              int cy = rev[nt].second;
              a1[i][j] = 1;
              a1[cx][cy] = a[cx][cy] - 1;
              for (int k = 0; k <= 3; k++) {
                if (i + dx[k] == cx && j + dy[k] == cy) {
                  a2[i][j] = dir[k];
                  a2[cx][cy] = dir[(k + 2) % 4];
                  break;
                }
              }
            }
          }
      }
    }
  puts("YES");
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++)
      printf("%d%c", a1[i][j], (j == m - 1 ? '\n' : ' '));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++)
      printf("%c%c", a2[i][j], (j == m - 1 ? '\n' : ' '));
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
