#include <bits/stdc++.h>
using namespace std;
class matching {
 public:
  vector<vector<int>> g;
  vector<int> pa;
  vector<int> pb;
  vector<int> was;
  int n, m;
  int res;
  int iter;
  matching(int _n, int _m) : n(_n), m(_m) {
    assert(0 <= n && 0 <= m);
    pa = vector<int>(n, -1);
    pb = vector<int>(m, -1);
    was = vector<int>(n, 0);
    g.resize(n);
    res = 0;
    iter = 0;
  }
  void add(int from, int to) {
    assert(0 <= from && from < n && 0 <= to && to < m);
    g[from].push_back(to);
  }
  bool dfs(int v) {
    was[v] = iter;
    for (int u : g[v]) {
      if (pb[u] == -1) {
        pa[v] = u;
        pb[u] = v;
        return true;
      }
    }
    for (int u : g[v]) {
      if (was[pb[u]] != iter && dfs(pb[u])) {
        pa[v] = u;
        pb[u] = v;
        return true;
      }
    }
    return false;
  }
  int solve() {
    while (true) {
      iter++;
      int add = 0;
      for (int i = 0; i < n; i++) {
        if (pa[i] == -1 && dfs(i)) {
          add++;
        }
      }
      if (add == 0) {
        break;
      }
      res += add;
    }
    return res;
  }
  int run_one(int v) {
    if (pa[v] != -1) {
      return 0;
    }
    iter++;
    return (int)dfs(v);
  }
};
int tt;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tt;
  while (tt--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    map<int, vector<pair<int, int>>> aux;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        aux[a[i][j]].push_back({i, j});
      }
    }
    vector<vector<int>> res(n, vector<int>(m));
    vector<vector<char>> g(n, vector<char>(m));
    auto get_dir = [&](int x, int y, int xx, int yy) {
      assert(abs(x - xx) + abs(y - yy) == 1);
      char ans;
      if (xx == x + 1) ans = 'D';
      if (xx == x - 1) ans = 'U';
      if (yy == y + 1) ans = 'R';
      if (yy == y - 1) ans = 'L';
      g[x][y] = ans;
    };
    bool ok = true;
    for (auto foo : aux) {
      vector<pair<int, int>> nodes = foo.second;
      int p = nodes.size();
      matching gr(p, p);
      map<pair<int, int>, int> id;
      for (int i = 0; i < p; i++) id[nodes[i]] = i;
      vector<int> dx = {1, 0, -1, 0};
      vector<int> dy = {0, 1, 0, -1};
      for (auto xy : nodes) {
        int x = xy.first;
        int y = xy.second;
        bool self = false;
        for (int i = 0; i < 4; i++) {
          int sx = x + dx[i];
          int sy = y + dy[i];
          if (sx < 0 || sx >= n || sy < 0 || sy >= m) continue;
          if (a[sx][sy] < a[x][y])
            self = true;
          else if (a[sx][sy] == a[x][y]) {
            gr.add(id[make_pair(x, y)], id[make_pair(sx, sy)]);
          }
        }
        if (self) gr.add(id[make_pair(x, y)], id[make_pair(x, y)]);
      }
      if (gr.solve() < p) {
        ok = false;
        break;
      }
      vector<int> pa = gr.pa;
      vector<vector<int>> cycles;
      vector<int> was(p);
      for (int i = 0; i < p; i++) {
        if (was[i]) continue;
        was[i] = 1;
        if (pa[i] == i) {
          int x = nodes[i].first;
          int y = nodes[i].second;
          for (int i = 0; i < 4; i++) {
            int sx = x + dx[i];
            int sy = y + dy[i];
            if (sx < 0 || sx >= n || sy < 0 || sy >= m) continue;
            if (a[sx][sy] < a[x][y]) {
              get_dir(x, y, sx, sy);
              res[x][y] = a[x][y] - a[sx][sy];
              break;
            }
          }
          continue;
        }
        cycles.push_back({i});
        while (pa[cycles.back().back()] != i) {
          cycles.back().push_back(pa[cycles.back().back()]);
          was[cycles.back().back()] = 1;
        }
      }
      for (vector<int> pos : cycles) {
        assert(pos.size() % 2 == 0);
        for (int i = 0; i < (int)pos.size(); i += 2) {
          int x = nodes[pos[i]].first, y = nodes[pos[i]].second;
          int sx = nodes[pos[i + 1]].first, sy = nodes[pos[i + 1]].second;
          get_dir(x, y, sx, sy);
          get_dir(sx, sy, x, y);
          res[x][y] = a[x][y] / 2;
          res[sx][sy] = (a[sx][sy] + 1) / 2;
        }
      }
    }
    if (!ok) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << res[i][j] << " ";
        }
        cout << "\n";
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << g[i][j] << " ";
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
