#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
template <class T>
using V = vector<T>;
template <class T, size_t SZ>
using AR = array<T, SZ>;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
T fstTrue(T lo, T hi, U first) {
  hi++;
  assert(lo <= hi);
  while (lo < hi) {
    T mid = lo + (hi - lo) / 2;
    first(mid) ? hi = mid : lo = mid + 1;
  }
  return lo;
}
template <class T, class U>
T lstTrue(T lo, T hi, U first) {
  lo--;
  assert(lo <= hi);
  while (lo < hi) {
    T mid = lo + (hi - lo + 1) / 2;
    first(mid) ? lo = mid : hi = mid - 1;
  }
  return lo;
}
template <class T>
void remDup(vector<T>& v) {
  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
}
template <class T, class U>
void erase(T& t, const U& u) {
  auto it = t.find(u);
  assert(it != end(t));
  t.erase(u);
}
template <class T>
void re(complex<T>& c);
template <class T, class U>
void re(pair<T, U>& p);
template <class T>
void re(vector<T>& v);
template <class T, size_t SZ>
void re(AR<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(db& d) {
  str t;
  re(t);
  d = stod(t);
}
void re(ld& d) {
  str t;
  re(t);
  d = stold(t);
}
template <class T, class... U>
void re(T& t, U&... u) {
  re(t);
  re(u...);
}
template <class T>
void re(complex<T>& c) {
  T a, b;
  re(a, b);
  c = {a, b};
}
template <class T, class U>
void re(pair<T, U>& p) {
  re(p.first, p.second);
}
template <class T>
void re(vector<T>& x) {
  for (auto& a : x) re(a);
}
template <class T, size_t SZ>
void re(AR<T, SZ>& x) {
  for (auto& a : x) re(a);
}
str to_string(char c) { return str(1, c); }
str to_string(const char* second) { return (str)second; }
str to_string(str second) { return second; }
str to_string(bool b) { return to_string((int)b); }
template <class T>
str to_string(complex<T> c) {
  stringstream ss;
  ss << c;
  return ss.str();
}
str to_string(vector<bool> v) {
  str res = "{";
  for (int i = (0); i < ((int)(v).size()); ++i) res += char('0' + v[i]);
  res += "}";
  return res;
}
template <size_t SZ>
str to_string(bitset<SZ> b) {
  str res = "";
  for (int i = (0); i < (SZ); ++i) res += char('0' + b[i]);
  return res;
}
template <class T, class U>
str to_string(pair<T, U> p);
template <class T>
str to_string(T v) {
  bool fst = 1;
  str res = "";
  for (const auto& x : v) {
    if (!fst) res += " ";
    fst = 0;
    res += to_string(x);
  }
  return res;
}
template <class T, class U>
str to_string(pair<T, U> p) {
  return to_string(p.first) + " " + to_string(p.second);
}
template <class T>
void pr(T x) {
  cout << to_string(x);
}
template <class T, class... U>
void pr(const T& t, const U&... u) {
  pr(t);
  pr(u...);
}
void ps() { pr("\n"); }
template <class T, class... U>
void ps(const T& t, const U&... u) {
  pr(t);
  if (sizeof...(u)) pr(" ");
  ps(u...);
}
void DBG() { cerr << "]" << endl; }
template <class T, class... U>
void DBG(const T& t, const U&... u) {
  cerr << to_string(t);
  if (sizeof...(u)) cerr << ", ";
  DBG(u...);
}
void setIn(str second) { freopen(second.c_str(), "r", stdin); }
void setOut(str second) { freopen(second.c_str(), "w", stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(str second = "") {
  unsyncIO();
  if ((int)(second).size()) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
struct Dinic {
  using F = ll;
  struct Edge {
    int to, rev;
    F flo, cap;
  };
  int N;
  V<V<Edge>> adj;
  void init(int _N) {
    N = _N;
    adj.resize(N);
  }
  void ae(int a, int b, F cap, F rcap = 0) {
    assert(min(cap, rcap) >= 0);
    adj[a].push_back({b, (int)(adj[b]).size(), 0, cap});
    adj[b].push_back({a, (int)(adj[a]).size() - 1, 0, rcap});
  }
  vi lev, ptr;
  bool bfs(int second, int t) {
    lev = ptr = vi(N);
    queue<int> q({second});
    lev[second] = 1;
    while ((int)(q).size()) {
      int u = q.front();
      q.pop();
      for (auto& e : adj[u]) {
        if (!lev[e.to] && e.cap - e.flo) q.push(e.to), lev[e.to] = lev[u] + 1;
      }
    }
    return lev[t];
  }
  F dfs(int v, int t, F flo) {
    if (v == t) return flo;
    for (int& i = ptr[v]; i < (int)(adj[v]).size(); i++) {
      Edge& e = adj[v][i];
      F dif = e.cap - e.flo;
      if (lev[e.to] != lev[v] + 1 || !dif) continue;
      if (F df = dfs(e.to, t, min(flo, dif))) {
        e.flo += df;
        adj[e.to][e.rev].flo -= df;
        return df;
      }
    }
    return 0;
  }
  F maxFlow(int second, int t) {
    F tot = 0;
    while (bfs(second, t))
      while (F df = dfs(second, t, numeric_limits<F>::max())) tot += df;
    return tot;
  }
};
int n, m;
V<vi> A;
int hsh(int a, int b) { return m * a + b; }
Dinic D;
vi adj[MX];
vb need;
vi mt;
bool bad = 0;
vi vis;
int tt;
bool dfs(int x) {
  if (vis[x] == tt) return 0;
  vis[x] = tt;
  for (int t : adj[x])
    if (mt[t] == -1 || dfs(mt[t])) return mt[t] = x, 1;
  return 0;
}
vi match(vi l, vi r) {
  mt = vi(n * m, -1);
  vb ok(n * m);
  for (auto& t : r) ok[t] = 1;
  vi res;
  for (auto& t : l) {
    vi now;
    for (auto& u : adj[t])
      if (ok[u]) now.push_back(u);
    adj[t] = now;
  }
  for (auto& t : l)
    if (need[t]) {
      tt++;
      if (!dfs(t)) {
        bad = 1;
        return {};
      }
      res.push_back(t);
    }
  for (auto& t : l)
    if (!need[t]) {
      tt++;
      if (dfs(t)) res.push_back(t);
    }
  return res;
}
void solve() {
  re(n, m);
  A = V<vi>(n, vi(m));
  re(A);
  need = vb(n * m);
  vis = vi(n * m);
  for (int i = (0); i < (n * m); ++i) adj[i].clear();
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j) {
      bool les = 0;
      for (int k = (0); k < (4); ++k) {
        int I = i + xd[k], J = j + yd[k];
        if (I < 0 || I >= n || J < 0 || J >= m) continue;
        les |= A[I][J] < A[i][j];
        if (A[I][J] == A[i][j]) adj[hsh(i, j)].push_back(hsh(I, J));
      }
      if (!les) {
        need[hsh(i, j)] = 1;
        0;
      }
    }
  }
  for (int i = (0); i < (n * m); ++i) 0;
  bad = 0;
  vi l, r;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) {
      if ((i + j) & 1)
        l.push_back(hsh(i, j));
      else
        r.push_back(hsh(i, j));
    }
  0;
  vi L = match(l, r);
  if (bad) {
    ps("NO");
    return;
  }
  0;
  vi R = match(r, L);
  0;
  if (bad) {
    ps("NO");
    return;
  }
  0;
  vs ans(n, str(m, '.'));
  V<vi> ANS(n, vi(m));
  auto con = [&](int x) -> pi { return {x / m, x % m}; };
  auto make_dir = [&](pi X, pi Y) {
    if (Y == make_pair(X.first + 1, X.second)) ans[X.first][X.second] = 'D';
    if (Y == make_pair(X.first - 1, X.second)) ans[X.first][X.second] = 'U';
    if (Y == make_pair(X.first, X.second + 1)) ans[X.first][X.second] = 'R';
    if (Y == make_pair(X.first, X.second - 1)) ans[X.first][X.second] = 'L';
  };
  auto make_edge = [&](int x, int y) {
    pi X = con(x), Y = con(y);
    ANS[X.first][X.second] = A[X.first][X.second] - 1;
    ANS[Y.first][Y.second] = 1;
    make_dir(X, Y);
    make_dir(Y, X);
  };
  for (int i = (0); i < (n * m); ++i)
    if (mt[i] != -1) {
      make_edge(mt[i], i);
      0;
    }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j)
      if (ans[i][j] == '.') {
        for (int k = (0); k < (4); ++k) {
          int I = i + xd[k], J = j + yd[k];
          if (I < 0 || I >= n || J < 0 || J >= m) continue;
          if (A[I][J] < A[i][j]) {
            ANS[i][j] = A[i][j] - A[I][J];
            make_dir({i, j}, {I, J});
          }
        }
      }
  ps("YES");
  for (auto& t : ANS) {
    for (auto& u : t) pr(u, ' ');
    ps();
  }
  for (auto& t : ans) {
    for (auto& u : t) pr(u, ' ');
    ps();
  }
}
int main() {
  setIO();
  int T;
  re(T);
  for (int i = (0); i < (T); ++i) solve();
}
