#include <bits/stdc++.h>
using namespace std;
struct Dinic {
  vector<int> lst, nxt, to, cap, lv, qu, cur;
  Dinic(int v) : lv(v), qu(v), cur(v) { lst.assign(v, -1); }
  void _add(int u, int v, int c) {
    nxt.push_back(lst[u]);
    lst[u] = nxt.size() - 1;
    to.push_back(v);
    cap.push_back(c);
  }
  void add(int u, int v, int c) {
    _add(u, v, c);
    _add(v, u, 0);
  }
  void bfs(int s) {
    lv.assign(lv.size(), 0);
    int nr = 0;
    qu[nr++] = s;
    lv[s] = 1;
    for (int i = 0; i < nr; i++) {
      int u = qu[i];
      cur[u] = lst[u];
      for (int p = lst[u]; p >= 0; p = nxt[p]) {
        int v = to[p];
        if (cap[p] && !lv[v]) {
          lv[v] = lv[u] + 1;
          qu[nr++] = v;
        }
      }
    }
  }
  int dfs(int u, int t, int fl) {
    int sum = 0;
    if (u == t || !fl) {
      return fl;
    }
    for (int p = cur[u]; p >= 0; p = nxt[p], cur[u] = p) {
      int v = to[p];
      if (cap[p] && lv[v] == lv[u] + 1) {
        int x = dfs(v, t, min(fl - sum, cap[p]));
        cap[p] -= x;
        cap[p ^ 1] += x;
        sum += x;
        if (fl <= sum) {
          break;
        }
      }
    }
    return sum;
  }
  int flow(int s, int t) {
    int cnt = 0;
    while (1) {
      bfs(s);
      if (!lv[t]) {
        break;
      }
      cnt += dfs(s, t, 1 << 30);
    }
    return cnt;
  }
};
int N, M;
int a[100005];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
char dc[] = "DURL";
int ga(int x, int y) { return a[x * M + y]; }
void solve() {
  cin >> N >> M;
  int s = N * M;
  int t = s + 1;
  int s_ = s + 2;
  int t_ = s + 3;
  Dinic dinic(t_ + 1);
  for (int i = 0; i < N * M; i++) cin >> a[i];
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      int p = i * M + j;
      int v = a[p];
      int has_lt = 0, has_eq = 0;
      for (int k = 0; k < 4; k++) {
        int x = i + dx[k];
        int y = j + dy[k];
        if (x < 0 || x >= N || y < 0 || y >= M) continue;
        if (ga(x, y) < v) {
          has_lt = 1;
        } else if (ga(x, y) == v) {
          has_eq = 1;
        }
      }
      if ((i + j) & 1) {
        dinic.add(s, p, 1);
        if (has_lt) {
          dinic.add(p, t_, 1);
        } else if (!has_eq) {
          cout << "NO" << endl;
          return;
        }
        for (int k = 0; k < 4; k++) {
          int x = p / M + dx[k];
          int y = p % M + dy[k];
          if (x < 0 || x >= N || y < 0 || y >= M) continue;
          if (a[p] == a[x * M + y]) dinic.add(p, x * M + y, 1);
        }
      } else {
        dinic.add(p, t, 1);
        if (has_lt) {
          dinic.add(s_, p, 1);
        } else if (!has_eq) {
          cout << "NO" << endl;
          return;
        }
      }
    }
  dinic.add(s, s_, (N * M + 1) / 2);
  dinic.add(t_, t, (N * M) / 2);
  dinic.add(s_, t_, N * M);
  int fl = dinic.flow(s, t);
  if (fl != N * M) {
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
  vector<int> pr(N * M), dr(N * M);
  pr.assign(N * M, -1);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      int u = i * M + j;
      if ((i + j) & 1) {
        for (int p = dinic.lst[u]; p >= 0; p = dinic.nxt[p]) {
          if (dinic.to[p] < N * M && !dinic.cap[p]) {
            pr[u] = dinic.to[p];
            pr[dinic.to[p]] = u;
          }
        }
      }
    }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (j) cout << " ";
      int u = i * M + j;
      if (pr[u] >= 0) {
        if ((i + j) & 1) {
          cout << 1;
        } else {
          cout << a[u] - 1;
        }
        for (int k = 0; k < 4; k++) {
          int x = u / M + dx[k];
          int y = u % M + dy[k];
          if (x < 0 || x >= N || y < 0 || y >= M) continue;
          if (x * M + y == pr[u]) {
            dr[u] = k;
            break;
          }
        }
      } else {
        for (int k = 0; k < 4; k++) {
          int x = u / M + dx[k];
          int y = u % M + dy[k];
          if (x < 0 || x >= N || y < 0 || y >= M) continue;
          if (a[x * M + y] < a[u]) {
            cout << a[u] - a[x * M + y];
            dr[u] = k;
            break;
          }
        }
      }
    }
    cout << endl;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (j) cout << " ";
      int u = i * M + j;
      cout << dc[dr[u]];
    }
    cout << endl;
  }
}
int main() {
  int T;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
