#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MN = 100010, ME = 1000010;
int src, snk, nno, ned;
int q[MN], fin[MN], pro[MN], dist[MN];
int flow[2 * ME], cap[2 * ME];
int sig[2 * ME], to[2 * ME];
inline void init(int _src, int _snk, int _n) {
  src = _src, snk = _snk, nno = _n, ned = 0;
  for (int i = 0; i <= nno; i++) fin[i] = -1;
}
inline void add(int u, int v, int c) {
  to[ned] = v, cap[ned] = c, flow[ned] = 0, sig[ned] = fin[u], fin[u] = ned++;
  to[ned] = u, cap[ned] = 0, flow[ned] = 0, sig[ned] = fin[v], fin[v] = ned++;
}
inline void reset(int _src, int _snk) {
  src = _src, snk = _snk;
  for (int i = 0; i < ned; i++) flow[i] = 0;
}
bool bfs() {
  int st, en, u, v;
  for (int i = 0; i <= nno; i++) dist[i] = -1;
  dist[src] = st = en = 0;
  q[en++] = src;
  while (st < en) {
    u = q[st++];
    for (int e = fin[u]; e >= 0; e = sig[e]) {
      v = to[e];
      if (flow[e] < cap[e] && dist[v] == -1) {
        dist[v] = dist[u] + 1;
        q[en++] = v;
      }
    }
  }
  return dist[snk] != -1;
}
int dfs(int u, int mn) {
  if (u == snk) return mn;
  int au, v;
  for (int &e = pro[u]; e >= 0; e = sig[e]) {
    v = to[e];
    if (flow[e] < cap[e] && dist[v] == dist[u] + 1)
      if (au = dfs(v, min(mn, cap[e] - flow[e]))) {
        flow[e] += au;
        flow[e ^ 1] -= au;
        return au;
      }
  }
  return 0;
}
int dinic() {
  int f = 0, au;
  while (bfs()) {
    for (int i = 0; i <= nno; i++) pro[i] = fin[i];
    while (au = dfs(src, INF)) f += au;
  }
  return f;
}
int n, m, in[MN], out[MN];
int mx[] = {1, -1, 0, 0};
int my[] = {0, 0, 1, -1};
char dir[] = {'D', 'U', 'R', 'L'};
vector<vector<int> > a;
inline int num(int i, int j) { return i * m + j; }
void solve() {
  cin >> n >> m;
  a = vector<vector<int> >(n, vector<int>(m));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) cin >> a[i][j];
  int s = n * m, t = s + 1, ss = t + 1, tt = ss + 1, sd = 0;
  init(ss, tt, tt);
  for (int i = 0; i < (tt); i++) in[i] = out[i] = 0;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      int f = 0;
      for (int l = 0; l < (4); l++) {
        int x = i + mx[l];
        int y = j + my[l];
        if (0 <= x && x < n && 0 <= y && y < m && a[i][j] > a[x][y]) {
          f = 1;
        }
      }
      if (!f) {
        for (int l = 0; l < (4); l++) {
          int x = i + mx[l];
          int y = j + my[l];
          if (0 <= x && x < n && 0 <= y && y < m && a[i][j] == a[x][y]) {
            int u = num(i, j);
            int v = num(x, y);
            if (i % 2 != j % 2) swap(u, v);
            add(u, v, 1);
          }
        }
      }
      if (i % 2 == j % 2) {
        if (f)
          add(s, num(i, j), 1);
        else
          out[s]++, in[num(i, j)]++;
      } else {
        if (f)
          add(num(i, j), t, 1);
        else
          out[num(i, j)]++, in[t]++;
      }
    }
  for (int i = 0; i < (tt); i++) {
    sd += in[i];
    if (in[i]) add(ss, i, in[i]);
    if (out[i]) add(i, tt, out[i]);
  }
  add(t, s, ME);
  int res = dinic();
  if (res == sd) {
    cout << "YES" << '\n';
    for (int i = 0; i < (n); i++) {
      for (int j = 0; j < (m); j++) {
        int f = 0;
        for (int e = fin[num(i, j)]; e >= 0; e = sig[e])
          if (to[e] < n * m && flow[e]) {
            if (i % 2 == j % 2)
              cout << a[i][j] - 1;
            else
              cout << 1;
            f = 1;
          }
        if (!f)
          for (int l = 0; l < (4); l++) {
            int x = i + mx[l];
            int y = j + my[l];
            if (0 <= x && x < n && 0 <= y && y < m && a[i][j] > a[x][y]) {
              cout << a[i][j] - a[x][y];
              break;
            }
          }
        cout << " ";
      }
      cout << '\n';
    }
    for (int i = 0; i < (n); i++) {
      for (int j = 0; j < (m); j++) {
        int f = 0;
        for (int e = fin[num(i, j)]; e >= 0; e = sig[e])
          if (to[e] < n * m && flow[e]) {
            int u = num(i, j);
            int v = to[e];
            if (u - m == v)
              cout << 'U';
            else if (u + m == v)
              cout << 'D';
            else if (u + 1 == v)
              cout << 'R';
            else
              cout << 'L';
            f = 1;
          }
        if (!f)
          for (int l = 0; l < (4); l++) {
            int x = i + mx[l];
            int y = j + my[l];
            if (0 <= x && x < n && 0 <= y && y < m && a[i][j] > a[x][y]) {
              cout << dir[l];
              break;
            }
          }
        cout << " ";
      }
      cout << '\n';
    }
  } else {
    cout << "NO" << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
