#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int n, m;
int p[5][2] = {0, 0, -1, 0, 1, 0, 0, 1, 0, -1};
bool lim[N];
int link[N], used[N];
int to[10 * N], lst[N], nxt[10 * N], cnt;
int ans[N];
char d[N];
int C(int x, int y) { return x * m + y; }
pair<int, int> C(int x) {
  return x < 0 | x >= n * m ? make_pair(-1, -1) : make_pair(x / m, x % m);
}
bool dfs(int u, int cas) {
  for (int k = lst[u]; k != 0; k = nxt[k]) {
    int v = to[k];
    if (used[v] != cas) {
      used[v] = cas;
      if (link[v] == -1 || dfs(link[v], cas)) {
        link[u] = v;
        link[v] = u;
        return 1;
      } else {
        if (lim[link[v]] == 0) {
          link[link[v]] = -1;
          link[u] = v;
          link[v] = u;
          return 1;
        }
      }
    }
  }
  return 0;
}
void Add(int u, int v) {
  cnt++, nxt[cnt] = lst[u], to[cnt] = v, lst[u] = cnt;
  cnt++, nxt[cnt] = lst[v], to[cnt] = u, lst[v] = cnt;
}
char T(int x, int y, int xx, int yy) {
  if (yy == y + 1) return 'R';
  if (yy == y - 1) return 'L';
  if (xx == x - 1) return 'U';
  if (xx == x + 1) return 'D';
}
void Find(int u) {
  pair<int, int> cor = C(u);
  int x = cor.first, y = cor.second;
  if (link[u] == -1) {
    for (int k = 1; k <= 4; k++) {
      int xx = x + p[k][0], yy = y + p[k][1];
      if (xx < 0 || xx >= n || yy < 0 || yy >= m || a[C(xx, yy)] >= a[u])
        continue;
      d[u] = T(x, y, xx, yy);
      ans[u] = a[u] - a[C(xx, yy)];
      break;
    }
  } else {
    int xx, yy;
    pair<int, int> corr;
    corr = C(link[u]);
    xx = corr.first, yy = corr.second;
    d[u] = T(x, y, xx, yy);
    if (ans[link[u]])
      ans[u] = a[u] - ans[link[u]];
    else
      ans[u] = 1;
  }
}
int anss[100][100];
void Judge(int x, int y) {
  used[C(x, y)] = 1;
  int xx = x, yy = y;
  if (d[C(x, y)] == 'D') xx++;
  if (d[C(x, y)] == 'L') yy--;
  if (d[C(x, y)] == 'U') xx--;
  if (d[C(x, y)] == 'R') yy++;
  if (used[C(xx, yy)])
    if (anss[xx][yy] != 0)
      anss[x][y] = ans[C(x, y)] + anss[xx][yy];
    else
      anss[x][y] = anss[xx][yy] = ans[C(x, y)] + ans[C(xx, yy)];
  else {
    Judge(xx, yy);
    if (anss[x][y] == 0) anss[x][y] = anss[xx][yy] + ans[C(x, y)];
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &m);
    for (int i = 0; i <= n * m - 1; i++) link[i] = -1;
    for (int i = 0; i <= n * m - 1; i++) scanf("%d", &a[i]);
    bool ok = 1;
    for (int i = 0; i <= n * m - 1; i++) {
      pair<int, int> xy = C(i);
      bool flag = 0;
      int num = 0;
      for (int k = 1; k <= 4; k++) {
        int x = xy.first + p[k][0], y = xy.second + p[k][1];
        if (x < 0 || x >= n || y < 0 || y >= m || a[C(x, y)] > a[i]) continue;
        flag = 1;
        if (a[C(x, y)] == a[i] && C(x, y) < i)
          Add(C(x, y), i);
        else if (a[C(x, y)] != a[i])
          num++;
      }
      if (!flag) {
        ok = 0;
        break;
      }
      if (num == 0) lim[i] = 1;
    }
    if (!ok) {
      printf("NO\n");
      continue;
    }
    int cas = 0;
    for (int i = 0; i <= n * m - 1; i++) {
      if (!lim[i]) continue;
      if (link[i] == -1 && !dfs(i, ++cas)) {
        ok = 0;
        break;
      }
    }
    if (!ok) {
      printf("NO\n");
      continue;
    }
    for (int i = 0; i <= n * m - 1; i++)
      if (ans[i] == 0) Find(i);
    printf("YES\n");
    for (int i = 0; i <= n - 1; i++) {
      for (int j = 0; j <= m - 1; j++) printf("%d ", ans[C(i, j)]);
      printf("\n");
    }
    for (int i = 0; i <= n - 1; i++) {
      for (int j = 0; j <= m - 1; j++) printf("%c ", d[C(i, j)]);
      printf("\n");
    }
    cnt = 0;
    for (int i = 0; i <= n * m - 1; i++)
      lim[i] = ans[i] = d[i] = used[i] = lst[i] = 0, link[i] = -1;
  }
}
