#include <bits/stdc++.h>
using namespace std;
const int N = 222222, M = N << 3, mod = 1e9 + 7;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  bool f = false;
  for (; ch < '0' || ch > '9'; ch = getchar()) f |= ch == '-';
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) return a = b, 1;
  return 0;
}
int ksm(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = (long long)a * a % mod)
    if (b & 1) res = (long long)res * a % mod;
  return res;
}
int r, c, n, s[N], val[N], S, T, SS, TT, cnt, head[N], to[M], nxt[M], cap[M],
    in[N];
char dir[N];
int id(int x, int y) { return (x - 1) * c + y; }
void add(int a, int b, int c) {
  to[++cnt] = b;
  nxt[cnt] = head[a];
  head[a] = cnt;
  cap[cnt] = c;
  to[++cnt] = a;
  nxt[cnt] = head[b];
  head[b] = cnt;
  cap[cnt] = 0;
}
bool check(int x, int y) {
  int now = id(x, y);
  if (x > 1 && s[now] > s[now - c]) {
    dir[now] = 'U';
    val[now] = s[now] - s[now - c];
    return true;
  }
  if (x < r && s[now] > s[now + c]) {
    dir[now] = 'D';
    val[now] = s[now] - s[now + c];
    return true;
  }
  if (y > 1 && s[now] > s[now - 1]) {
    dir[now] = 'L';
    val[now] = s[now] - s[now - 1];
    return true;
  }
  if (y < c && s[now] > s[now + 1]) {
    dir[now] = 'R';
    val[now] = s[now] - s[now + 1];
    return true;
  }
  return false;
}
int maxf, dep[N], cur[N], qu[N], fr, re;
bool bfs() {
  memset(dep, -1, n + 5 << 2);
  memcpy(cur, head, n + 5 << 2);
  qu[fr = dep[S] = 0] = S;
  re = 1;
  while (fr < re) {
    int u = qu[fr++];
    for (int i = head[u]; i; i = nxt[i])
      if (dep[to[i]] == -1 && cap[i]) {
        dep[to[i]] = dep[u] + 1;
        qu[re++] = to[i];
      }
  }
  return ~dep[T];
}
int dfs(int x, int lim) {
  if (x == T || !lim) return lim;
  int f, flow = 0;
  for (int &i = cur[x]; i; i = nxt[i])
    if (dep[to[i]] == dep[x] + 1 && (f = dfs(to[i], min(lim, cap[i])))) {
      flow += f;
      lim -= f;
      cap[i] -= f;
      cap[i ^ 1] += f;
      if (!lim) break;
    }
  return flow;
}
void solve() {
  read(r);
  read(c);
  n = r * c;
  SS = n + 1;
  TT = SS + 1;
  S = TT + 1;
  T = S + 1;
  memset(head, 0, n + 5 << 2);
  memset(in, 0, sizeof in);
  cnt = 1;
  add(TT, SS, n);
  for (int i = 1; i <= n; ++i) read(s[i]);
  for (int x = 1; x <= r; ++x)
    for (int y = 1; y <= c; ++y) {
      int now = id(x, y);
      if (x + y & 1) {
        if (check(x, y))
          add(SS, now, 1);
        else {
          --in[SS];
          ++in[now];
        }
        if (x > 1 && s[now] == s[now - c]) add(now, now - c, 1);
        if (x < r && s[now] == s[now + c]) add(now, now + c, 1);
        if (y > 1 && s[now] == s[now - 1]) add(now, now - 1, 1);
        if (y < c && s[now] == s[now + 1]) add(now, now + 1, 1);
      } else {
        if (check(x, y))
          add(now, TT, 1);
        else {
          --in[now];
          ++in[TT];
        }
      }
    }
  for (int i = 1; i <= TT; ++i)
    if (in[i] > 0) {
      add(S, i, in[i]);
      maxf += in[i];
    } else if (in[i] < 0)
      add(i, T, -in[i]);
  while (bfs()) maxf -= dfs(S, maxf);
  if (maxf) {
    puts("NO");
    return;
  }
  for (int i = 2; i < cnt; i += 2)
    if (!cap[i]) {
      int Azusa = to[i], Mrsrz = to[i ^ 1];
      if (Azusa > Mrsrz) swap(Azusa, Mrsrz);
      if (Mrsrz > n) continue;
      if (Mrsrz - Azusa == c) {
        dir[Azusa] = 'D';
        dir[Mrsrz] = 'U';
      } else if (Mrsrz - Azusa == 1) {
        dir[Azusa] = 'R';
        dir[Mrsrz] = 'L';
      }
      val[Azusa] = 1;
      val[Mrsrz] = s[Mrsrz] - 1;
    }
  puts("YES");
  for (int i = 1; i <= n; ++i) printf("%d%c", val[i], " \n"[!(i % c)]);
  for (int i = 1; i <= n; ++i) {
    putchar(dir[i]);
    putchar(" \n"[!(i % c)]);
  }
}
int Test;
int main() {
  read(Test);
  while (Test--) solve();
}
