#include <bits/stdc++.h>
using namespace std;
namespace Dinic {
struct edge {
  int from, to, flow, next;
} E[400000 * 2 + 5];
int head[100000 + 5], cur[100000 + 5];
int esz = 1;
vector<int> nodes;
void add_edge(int u, int v, int w) {
  nodes.push_back(u);
  nodes.push_back(v);
  esz++;
  E[esz].from = u;
  E[esz].to = v;
  E[esz].flow = w;
  E[esz].next = head[u];
  head[u] = esz;
  esz++;
  E[esz].from = v;
  E[esz].to = u;
  E[esz].flow = 0;
  E[esz].next = head[v];
  head[v] = esz;
}
int deep[100000 + 5];
bool bfs(int s, int t) {
  for (int first : nodes) deep[first] = 0;
  queue<int> q;
  deep[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int first = q.front();
    q.pop();
    for (int i = head[first]; i; i = E[i].next) {
      int second = E[i].to;
      if (!deep[second] && E[i].flow) {
        deep[second] = deep[first] + 1;
        q.push(second);
      }
    }
  }
  return deep[t] > 0;
}
int dfs(int first, int t, int minf) {
  if (first == t) return minf;
  int rest = minf, k;
  for (int &i = cur[first]; i; i = E[i].next) {
    int second = E[i].to;
    if (E[i].flow && deep[second] == deep[first] + 1) {
      k = dfs(second, t, min(rest, E[i].flow));
      E[i].flow -= k;
      E[i ^ 1].flow += k;
      rest -= k;
      if (k == 0) deep[second] = 0;
      if (rest == 0) break;
    }
  }
  return minf - rest;
}
int dinic(int s, int t) {
  int ans = 0, now;
  while (bfs(s, t)) {
    for (int first : nodes) cur[first] = head[first];
    while ((now = dfs(s, t, 0x3f3f3f3f))) ans += now;
  }
  return ans;
}
void clear() {
  esz = 1;
  for (int first : nodes) head[first] = 0;
  nodes.clear();
}
}  // namespace Dinic
namespace bdf {
struct edgeb {
  int from, to, lb, rb;
} E[400000 + 5];
int esz = 0;
int suml = 0;
vector<int> nodes;
void add_edge(int u, int v, int l, int r) {
  esz++;
  E[esz].from = u;
  E[esz].to = v;
  E[esz].lb = l;
  E[esz].rb = r;
  suml += l;
  nodes.push_back(u);
  nodes.push_back(v);
}
int dflow[100000 + 5];
int solve(int s, int t) {
  Dinic::clear();
  int ss = t + 1, tt = t + 2;
  add_edge(t, s, 0, 0x3f3f3f3f);
  sort(nodes.begin(), nodes.end());
  nodes.resize(unique(nodes.begin(), nodes.end()) - nodes.begin());
  for (int i = 1; i <= esz; i++) {
    dflow[E[i].to] += E[i].lb;
    dflow[E[i].from] -= E[i].lb;
    Dinic::add_edge(E[i].from, E[i].to, E[i].rb - E[i].lb);
  }
  int sum = 0;
  for (int i : nodes) {
    if (dflow[i] > 0) {
      Dinic::add_edge(ss, i, dflow[i]);
      sum += dflow[i];
    } else if (dflow[i] < 0)
      Dinic::add_edge(i, tt, -dflow[i]);
  }
  int delta = Dinic::dinic(ss, tt);
  if (delta != sum)
    return -1;
  else
    return delta + suml;
}
void clear() {
  esz = 0;
  suml = 0;
  for (int first : nodes) dflow[first] = 0;
  nodes.clear();
  Dinic::clear();
}
}  // namespace bdf
int T, n, m;
vector<int> c[100000 + 5];
vector<int> ans[100000 + 5];
vector<pair<int, int> > poi;
inline int gid(int first, int second) { return (first - 1) * m + second; }
inline int gx(int id) { return id % m == 0 ? id / m : id / m + 1; }
inline int gy(int id) { return id % m == 0 ? m : id % m; }
const char dirs[5] = "RLDU";
const int dirx[4] = {0, 0, 1, -1}, diry[4] = {1, -1, 0, 0};
void solve() {
  poi.clear();
  for (int i = 1; i <= n; i++) ans[i].resize(m + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) poi.push_back(make_pair(i, j));
  sort(poi.begin(), poi.end(), [&](pair<int, int> p, pair<int, int> q) -> bool {
    return c[p.first][p.second] < c[q.first][q.second];
  });
  for (int l = 0, r; l < (int)poi.size(); l++) {
    r = l;
    while (r + 1 < (int)poi.size() &&
           c[poi[l].first][poi[l].second] ==
               c[poi[r + 1].first][poi[r + 1].second])
      r++;
    bdf::clear();
    int s = n * m + 1, t = n * m + 2;
    for (int i = l; i <= r; i++) {
      int first = poi[i].first, second = poi[i].second;
      int flag = 1;
      for (int k = 0; k < 4; k++) {
        int xx = first + dirx[k], yy = second + diry[k];
        if (xx >= 1 && xx <= n && yy >= 1 && yy <= m) {
          if (c[xx][yy] < c[first][second]) {
            flag = 0;
            ans[first][second] = k;
          } else if (c[xx][yy] == c[first][second]) {
            if ((first + second) % 2)
              bdf::add_edge(gid(first, second), gid(xx, yy), 0, 1);
          }
        }
      }
      if ((first + second) % 2)
        bdf::add_edge(s, gid(first, second), flag, 1);
      else
        bdf::add_edge(gid(first, second), t, flag, 1);
    }
    if (c[poi[l].first][poi[l].second] == 3) {
      s = n * m + 1;
    }
    if (bdf::solve(s, t) == -1) {
      puts("NO");
      return;
    } else {
      for (int i = l; i <= r; i++) {
        int first = poi[i].first, second = poi[i].second;
        if ((first + second) % 2) {
          int u = gid(first, second);
          for (int j = Dinic::head[u]; j; j = Dinic::E[j].next) {
            int v = Dinic::E[j].to;
            if (v <= n * m && Dinic::E[j ^ 1].flow) {
              int xx = gx(v), yy = gy(v);
              for (int k = 0; k < 4; k++)
                if (first + dirx[k] == xx && second + diry[k] == yy)
                  ans[first][second] = k;
              ans[xx][yy] = ans[first][second] ^ 1;
              break;
            }
          }
        }
      }
    }
    l = r;
  }
  puts("YES");
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int first = i + dirx[ans[i][j]], second = j + diry[ans[i][j]];
      if (c[i][j] == c[first][second])
        printf("%d ", (c[i][j] + (i + j) % 2) / 2);
      else
        printf("%d ", c[i][j] - c[first][second]);
    }
    puts("");
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%c ", dirs[ans[i][j]]);
    puts("");
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
      c[i].resize(m + 1);
      for (int j = 1; j <= m; j++) scanf("%d", &c[i][j]);
    }
    solve();
  }
}
