#include <bits/stdc++.h>
namespace kactl {
using namespace std;
struct Dinic {
  struct Edge {
    int to, rev;
    long long c, oc;
    long long flow() const { return max(oc - c, 0LL); }
  };
  vector<int> lvl, ptr, q;
  vector<vector<Edge>> adj;
  Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
  void addEdge(int a, int b, long long c, long long rcap = 0) {
    adj[a].push_back({b, (int)(adj[b]).size(), c, c});
    adj[b].push_back({a, (int)(adj[a]).size() - 1, rcap, rcap});
  }
  long long dfs(int v, int t, long long f) {
    if (v == t || !f) return f;
    for (int& i = ptr[v]; i < (int)(adj[v]).size(); i++) {
      Edge& e = adj[v][i];
      if (lvl[e.to] == lvl[v] + 1)
        if (long long p = dfs(e.to, t, min(f, e.c))) {
          e.c -= p, adj[e.to][e.rev].c += p;
          return p;
        }
    }
    return 0;
  }
  long long calc(int s, int t) {
    long long flow = 0;
    q[0] = s;
    for (int L = 0; L < (31); ++L) do {
        lvl = ptr = vector<int>((int)(q).size());
        int qi = 0, qe = lvl[s] = 1;
        while (qi < qe && !lvl[t]) {
          int v = q[qi++];
          for (Edge e : adj[v])
            if (!lvl[e.to] && e.c >> (30 - L))
              q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
        }
        while (long long p = dfs(s, t, LLONG_MAX)) flow += p;
      } while (lvl[t]);
    return flow;
  }
  bool leftOfMinCut(int a) { return lvl[a] != 0; }
};
}  // namespace kactl
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int NCASES;
  cin >> NCASES;
  while (NCASES--) {
    int N, M;
    cin >> N >> M;
    vector<int> G(N * M);
    for (auto& v : G) cin >> v;
    const int V = N * M + 4;
    int S = N * M;
    int T = N * M + 1;
    int S2 = N * M + 2;
    int T2 = N * M + 3;
    kactl::Dinic flower(V);
    vector<int> cost(N * M);
    vector<char> dir(N * M, '\0');
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        if (i - 1 >= 0 && G[i * M + j] > G[(i - 1) * M + j]) {
          cost[i * M + j] = G[i * M + j] - G[(i - 1) * M + j];
          dir[i * M + j] = 'U';
        } else if (i + 1 < N && G[i * M + j] > G[(i + 1) * M + j]) {
          cost[i * M + j] = G[i * M + j] - G[(i + 1) * M + j];
          dir[i * M + j] = 'D';
        } else if (j - 1 >= 0 && G[i * M + j] > G[i * M + (j - 1)]) {
          cost[i * M + j] = G[i * M + j] - G[i * M + (j - 1)];
          dir[i * M + j] = 'L';
        } else if (j + 1 < M && G[i * M + j] > G[i * M + (j + 1)]) {
          cost[i * M + j] = G[i * M + j] - G[i * M + (j + 1)];
          dir[i * M + j] = 'R';
        }
        if (dir[i * M + j]) {
          if ((i ^ j) & 1) {
            flower.addEdge(S, i * M + j, 1);
          } else {
            flower.addEdge(i * M + j, T, 1);
          }
        }
      }
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        if (i + 1 < N && G[i * M + j] == G[(i + 1) * M + j]) {
          int a = i * M + j;
          int b = (i + 1) * M + j;
          if ((i ^ j) & 1) std::swap(a, b);
          flower.addEdge(a, b, 1);
        }
        if (j + 1 < M && G[i * M + j] == G[i * M + (j + 1)]) {
          int a = i * M + j;
          int b = i * M + (j + 1);
          if ((i ^ j) & 1) std::swap(a, b);
          flower.addEdge(a, b, 1);
        }
      }
    }
    int num_even = 0;
    int num_odd = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        if ((i ^ j) & 1) {
          num_odd++;
          flower.addEdge(i * M + j, T2, 1);
        } else {
          num_even++;
          flower.addEdge(S2, i * M + j, 1);
        }
      }
    }
    flower.addEdge(S2, T, num_odd);
    flower.addEdge(S, T2, num_even);
    flower.addEdge(T, S, N * M);
    int tot_flow = int(flower.calc(S2, T2));
    if (tot_flow != N * M) {
      cout << "NO" << '\n';
      continue;
    } else {
      cout << "YES" << '\n';
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
          if ((i ^ j) & 1) continue;
          for (const auto& e : flower.adj[i * M + j]) {
            if (0 <= e.to && e.to < N * M && e.flow()) {
              int i2 = e.to / M;
              int j2 = e.to % M;
              assert(abs(i - i2) + abs(j - j2) == 1);
              assert(G[i * M + j] == G[i2 * M + j2]);
              cost[i * M + j] = G[i * M + j] / 2;
              cost[i2 * M + j2] = (G[i * M + j] + 1) / 2;
              if (i2 - i == 1) {
                dir[i * M + j] = 'D';
                dir[i2 * M + j2] = 'U';
              } else if (i2 - i == -1) {
                dir[i * M + j] = 'U';
                dir[i2 * M + j2] = 'D';
              } else if (j2 - j == 1) {
                dir[i * M + j] = 'R';
                dir[i2 * M + j2] = 'L';
              } else if (j2 - j == -1) {
                dir[i * M + j] = 'L';
                dir[i2 * M + j2] = 'R';
              } else
                assert(false);
            }
          }
        }
      }
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
          cout << cost[i * M + j] << " \n"[j + 1 == M];
        }
      }
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
          assert(dir[i * M + j]);
          cout << dir[i * M + j] << " \n"[j + 1 == M];
        }
      }
    }
  }
  return 0;
}
