#include <bits/stdc++.h>
using namespace std;
template <typename C, typename R = C, bool lb = false>
struct dinic {
  static_assert(std::is_arithmetic<C>::value, "flow_type must be arithmetic");
  static_assert(std::is_arithmetic<R>::value, "result_type must be arithmetic");
  static const C oo = std::numeric_limits<C>::max();
  struct edge {
    int src;
    int dst;
    int rev;
    C cap, flow;
    edge(int src, int dst, int rev, C cap, C flow)
        : src(src), dst(dst), rev(rev), cap(cap), flow(flow) {}
  };
  dinic(int n)
      : adj(n + 2 * lb),
        que(n + 2 * lb),
        level(n + 2 * lb),
        edge_pos(n + 2 * lb) {}
  int add_edge(int src, int dst, C cap, C rcap = 0) {
    adj[src].emplace_back(src, dst, (int)adj[dst].size(), cap, lb ? rcap : 0);
    if (src == dst) adj[src].back().rev++;
    adj[dst].emplace_back(dst, src, (int)adj[src].size() - 1, lb ? 0 : rcap, 0);
    return (int)adj[src].size() - 1 - (src == dst);
  }
  inline bool side_of_S(int u) { return level[u] == -1; }
  R max_flow(int source, int sink) {
    R flow = 0;
    while (true) {
      int front = 0, back = 0;
      std::fill(level.begin(), level.end(), -1);
      for (level[que[back++] = sink] = 0; front < back && level[source] == -1;
           ++front) {
        int u = que[front];
        for (const edge &e : adj[u])
          if (level[e.dst] == -1 && rev(e).flow < rev(e).cap)
            level[que[back++] = e.dst] = 1 + level[u];
      }
      if (level[source] == -1) break;
      std::fill(edge_pos.begin(), edge_pos.end(), 0);
      std::function<C(int, C)> find_path = [&](int from, C res) {
        if (from == sink) return res;
        for (int &ept = edge_pos[from]; ept < (int)adj[from].size(); ++ept) {
          edge &e = adj[from][ept];
          if (e.flow == e.cap || level[e.dst] + 1 != level[from]) continue;
          C push = find_path(e.dst, std::min(res, e.cap - e.flow));
          if (push > 0) {
            e.flow += push;
            rev(e).flow -= push;
            if (e.flow == e.cap) ++ept;
            return push;
          }
        }
        return static_cast<C>(0);
      };
      for (C f; (f = find_path(source, oo)) > 0;) flow += f;
    }
    return flow;
  }
  R max_flow_lb(int source, int sink) {
    int n = adj.size() - 2;
    vector<C> delta(n + 2);
    for (int u = 0; u < n; ++u)
      for (auto &e : adj[u]) {
        delta[u] -= e.flow;
        delta[e.dst] += e.flow;
      }
    R sum = 0;
    int s = n, t = n + 1;
    for (int u = 0; u < n; ++u) {
      if (delta[u] > 0) {
        add_edge(s, u, delta[u], 0);
        sum += delta[u];
      } else if (delta[u] < 0)
        add_edge(u, t, -delta[u], 0);
    }
    add_edge(sink, source, oo, 0);
    if (max_flow(s, t) != sum) return -1;
    R flow = adj[sink].back().flow;
    adj[sink].pop_back();
    adj[source].pop_back();
    return flow;
  }
  std::vector<std::vector<edge>> adj;

 private:
  std::vector<int> que;
  std::vector<int> level;
  std::vector<int> edge_pos;
  inline edge &rev(const edge &e) { return adj[e.dst][e.rev]; }
};
const int mov[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const char cmov[4] = {'D', 'U', 'R', 'L'};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (auto &i : a)
      for (auto &j : i) cin >> j;
    dinic<int, int, true> d(n * m * 2 + 2);
    int source = n * m * 2, sink = source + 1;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        bool g = false;
        for (int k = 0; k < 4; ++k) {
          int ni = i + mov[k][0];
          int nj = j + mov[k][1];
          if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
            g |= a[i][j] > a[ni][nj];
            if (((i ^ j) & 1) && a[i][j] == a[ni][nj])
              d.add_edge(i * m + j, n * m + ni * m + nj, 1);
          }
        }
        if ((i ^ j) & 1)
          d.add_edge(source, i * m + j, 1, !g);
        else
          d.add_edge(n * m + i * m + j, sink, 1, !g);
      }
    if (d.max_flow_lb(source, sink) == -1)
      cout << "NO\n";
    else {
      vector<vector<pair<int, char>>> ans(n, vector<pair<int, char>>(m));
      for (int i = 0; i < n * m; ++i)
        for (auto j : d.adj[i])
          if (j.dst < 2 * n * m && j.flow) {
            if ((j.dst - n * m) / m == i / m) {
              int x = i % m, y = (j.dst - n * m) % m;
              if (x > y) swap(x, y);
              ans[i / m][x] = {1, 'R'};
              ans[i / m][y] = {a[i / m][x] - 1, 'L'};
            } else {
              int x = i / m, y = (j.dst - n * m) / m;
              if (x > y) swap(x, y);
              ans[x][i % m] = {1, 'D'};
              ans[y][i % m] = {a[x][i % m] - 1, 'U'};
            }
          }
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
          if (ans[i][j].first == 0)
            for (int k = 0; k < 4; ++k) {
              int ni = i + mov[k][0];
              int nj = j + mov[k][1];
              if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[i][j] > a[ni][nj])
                ans[i][j] = {a[i][j] - a[ni][nj], cmov[k]};
            }
      cout << "YES\n";
      for (auto &i : ans)
        for (auto &j : i) cout << j.first << " \n"[&j == &i.back()];
      for (auto &i : ans)
        for (auto &j : i) cout << j.second << " \n"[&j == &i.back()];
    }
  }
  return 0;
}
