Problem: Nash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands. 

This board game is played on the n× n board. Rows and columns of this board are numbered from 1 to n. The cell on the intersection of the r-th row and c-th column is denoted by (r, c).

Some cells on the board are called blocked zones. On each cell of the board, there is written one of the following 5 characters — U, D, L, R or X — instructions for the player. Suppose that the current cell is (r, c). If the character is R, the player should move to the right cell (r, c+1), for L the player should move to the left cell (r, c-1), for U the player should move to the top cell (r-1, c), for D the player should move to the bottom cell (r+1, c). Finally, if the character in the cell is X, then this cell is the blocked zone. The player should remain in this cell (the game for him isn't very interesting from now on).

It is guaranteed that the characters are written in a way that the player will never have to step outside of the board, no matter at which cell he starts.

As a player starts from a cell, he moves according to the character in the current cell. The player keeps moving until he lands in a blocked zone. It is also possible that the player will keep moving infinitely long.

For every of the n^2 cells of the board Alice, your friend, wants to know, how will the game go, if the player starts in this cell. For each starting cell of the board, she writes down the cell that the player stops at, or that the player never stops at all. She gives you the information she has written: for each cell (r, c) she wrote: 

  * a pair (x,y), meaning if a player had started at (r, c), he would end up at cell (x,y). 
  * or a pair (-1,-1), meaning if a player had started at (r, c), he would keep moving infinitely long and would never enter the blocked zone. 



It might be possible that Alice is trying to fool you and there's no possible grid that satisfies all the constraints Alice gave you. For the given information Alice provided you, you are required to decipher a possible board, or to determine that such a board doesn't exist. If there exist several different boards that satisfy the provided information, you can find any of them.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10^{3}) — the side of the board.

The i-th of the next n lines of the input contains 2n integers x_1, y_1, x_2, y_2, ..., x_n, y_n, where (x_j, y_j) (1 ≤ x_j ≤ n, 1 ≤ y_j ≤ n, or (x_j,y_j)=(-1,-1)) is the pair written by Alice for the cell (i, j). 

Output

If there doesn't exist a board satisfying the information that Alice gave you, print a single line containing INVALID. 

Otherwise, in the first line print VALID. In the i-th of the next n lines, print the string of n characters, corresponding to the characters in the i-th row of the suitable board you found. Each character of a string can either be U, D, L, R or X. If there exist several different boards that satisfy the provided information, you can find any of them.

Examples

Input


2
1 1 1 1
2 2 2 2


Output


VALID
XL
RX


Input


3
-1 -1 -1 -1 -1 -1
-1 -1 2 2 -1 -1
-1 -1 -1 -1 -1 -1


Output


VALID
RRD
UXD
ULL

Note

For the sample test 1 :

The given grid in output is a valid one. 

  * If the player starts at (1,1), he doesn't move any further following X and stops there. 
  * If the player starts at (1,2), he moves to left following L and stops at (1,1). 
  * If the player starts at (2,1), he moves to right following R and stops at (2,2). 
  * If the player starts at (2,2), he doesn't move any further following X and stops there. 



The simulation can be seen below : 

<image>

For the sample test 2 : 

The given grid in output is a valid one, as a player starting at any cell other than the one at center (2,2), keeps moving in an infinitely long cycle and never stops. Had he started at (2,2), he wouldn't have moved further following instruction X .

The simulation can be seen below : 

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int ceilingOf(double a) {
  if (a == (int)a) return (int)a;
  return (int)a + 1;
}
int floorOf(double a) { return (int)a; }
long long maximum(long long x, long long y) {
  if (x > y) return x;
  return y;
}
int minimum(int x, int y) {
  if (x < y) return x;
  return y;
}
void shuffle_array(int arr[], int n) { random_shuffle(arr, arr + n); }
void print_array(int arr[], int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << '\n';
}
void print_array(bool arr[], int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << '\n';
}
void print_array(long long arr[], int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << '\n';
}
void swap(int* a, int* b) {
  int t = *a;
  *a = *b;
  *b = t;
}
void print_array(char** arr, int N, int M) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) cout << arr[i][j] << " ";
    cout << '\n';
  }
}
void print_array(int** arr, int N, int M) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) cout << arr[i][j] << " ";
    cout << '\n';
  }
}
void print_array(long long** arr, int N, int M) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) cout << arr[i][j] << " ";
    cout << '\n';
  }
}
int floodArea(int N, int M, bool** pos, bool** visited, int i, int j) {
  if (pos[i][j] == 0) return 0;
  list<int> a;
  int maxar = -INT_MAX;
  visited[i][j] = 1;
  a.push_back((N + M) * i + j);
  int counts = 1;
  while (!a.empty()) {
    int index = a.back();
    a.pop_back();
    int row = index / (M + N);
    int col = index % (M + N);
    if ((row + 1 < N) && visited[row + 1][col] == 0 &&
        pos[row + 1][col] == pos[i][j]) {
      visited[row + 1][col] = 1;
      a.push_back((M + N) * (row + 1) + col);
      counts++;
    }
    if ((col + 1 < M) && visited[row][col + 1] == 0 &&
        pos[row][col + 1] == pos[i][j]) {
      visited[row][col + 1] = 1;
      a.push_back((M + N) * row + (col + 1));
      counts++;
    }
    if ((row - 1 >= 0) && visited[row - 1][col] == 0 &&
        pos[row - 1][col] == pos[i][j]) {
      visited[row - 1][col] = 1;
      a.push_back((M + N) * (row - 1) + col);
      counts++;
    }
    if ((col - 1 >= 0) && visited[row][col - 1] == 0 &&
        pos[row][col - 1] == pos[i][j]) {
      visited[row][col - 1] = 1;
      a.push_back((M + N) * row + (col - 1));
      counts++;
    }
  }
  if (counts > maxar) {
    maxar = counts;
  }
  return maxar;
}
void deleteFlood(int N, int M, int** pos, int** visited, int i, int j) {
  int val = pos[i][j];
  pos[i][j] = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) visited[i][j] = 0;
  list<int> a;
  int maxar = -INT_MAX;
  visited[i][j] = 1;
  a.push_back((N + M) * i + j);
  int counts = 1;
  while (!a.empty()) {
    int index = a.back();
    a.pop_back();
    int row = index / (M + N);
    int col = index % (M + N);
    if ((row + 1 < N)) {
      if (visited[row + 1][col] == 0 && pos[row + 1][col] == val) {
        visited[row + 1][col] = 1;
        a.push_back((M + N) * (row + 1) + col);
        pos[row + 1][col] = 0;
      }
    }
    if ((col + 1 < M)) {
      if (visited[row][col + 1] == 0 && pos[row][col + 1] == val) {
        visited[row][col + 1] = 1;
        a.push_back((M + N) * row + (col + 1));
        pos[row][col + 1] = 0;
      }
    }
    if ((row - 1 >= 0)) {
      if (visited[row - 1][col] == 0 && pos[row - 1][col] == val) {
        visited[row - 1][col] = 1;
        a.push_back((M + N) * (row - 1) + col);
        pos[row - 1][col] = 0;
      }
    }
    if ((col - 1 >= 0)) {
      if (visited[row][col - 1] == 0 && pos[row][col - 1] == val) {
        visited[row][col - 1] = 1;
        a.push_back((M + N) * row + (col - 1));
        pos[row][col - 1] = 0;
      }
    }
  }
}
void print_vector(vector<int> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<char> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<long long> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<double> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<int> amount, int N) {
  for (auto i = amount.begin(); i != amount.begin() + N; i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<string> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<bool> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<pair<int, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first << " ";
  cout << '\n';
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).second << " ";
  cout << '\n';
}
void print_vector(vector<pair<long long, long long>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first << " ";
  cout << '\n';
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).second << " ";
  cout << '\n';
}
void print_vector(vector<pair<string, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first << " " << (*i).second << '\n';
  cout << '\n';
}
void print_vector(vector<pair<pair<int, int>, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first.first << " " << (*i).first.second << " " << (*i).second
         << '\n';
  cout << '\n';
}
void print_vector(vector<pair<int, pair<int, int>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first << " " << (*i).second.first << " " << (*i).second.second
         << '\n';
  cout << '\n';
}
void print_vector(vector<tuple<int, int, int, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << get<0>(*i) << " " << get<1>(*i) << " " << get<2>(*i) << " "
         << get<3>(*i) << '\n';
  cout << '\n';
}
void print_vector(vector<vector<string>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<char>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<long long>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<pair<long long, long long>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
  }
  cout << '\n';
}
void print_vector(vector<vector<vector<int>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<vector<long long>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<bool>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_set(set<int> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_set(set<pair<int, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << i->first << " " << i->second << '\n';
  cout << '\n';
}
void print_vector(vector<set<int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_set(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<pair<int, int>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
  }
}
void print_set(set<string> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_map(map<int, vector<int>> m) {
  for (map<int, vector<int>>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_vector(i->second);
  }
}
void print_map(map<string, vector<string>> m) {
  for (map<string, vector<string>>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_vector(i->second);
  }
}
void print_map(map<string, vector<bool>> m) {
  for (map<string, vector<bool>>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_vector(i->second);
  }
}
void print_map(map<string, set<string>> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_set(i->second);
  }
}
void print_map_vector(map<string, vector<bool>> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_vector(i->second);
  }
}
void print_map(map<int, bool> m) {
  for (map<int, bool>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " " << i->second << '\n';
  }
}
void print_map(map<int, int> m) {
  for (map<int, int>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " " << i->second << '\n';
  }
}
void print_map(map<char, vector<string>> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << '\n';
    cout << '\t';
    print_vector(i->second);
  }
}
void print_map(map<char, int> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << '\n';
    cout << '\t' << i->second << '\n';
  }
}
void print_map(map<pair<int, int>, int> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first.first << " " << i->first.second << " " << i->second
         << '\n';
  }
}
bool comp(pair<int, int> x, pair<int, int> y) {
  if (x.second > y.second) {
    return 0;
  }
  if (x.second == y.second) {
    return x.first < y.first;
  }
  return 1;
}
class segment_tree {
  vector<int> tree;
  int height;
  int maxSize;
  int STARTINDEX = 0;
  int ENDINDEX;

 public:
  segment_tree(int n) {
    height = (int)ceilingOf(log2(n));
    maxSize = (1 << (height + 1)) - 1;
    tree.resize(maxSize);
    ENDINDEX = (1 << height) - 1;
  }

 public:
  int leftChild(int k) { return 2 * k + 1; }

 public:
  int rightChild(int k) { return 2 * k + 2; }

 public:
  void buildSegTree(vector<int>& A) {
    A.resize(1 << height, 0);
    buildSegTreeRec(STARTINDEX, ENDINDEX, 0, A);
  }

 public:
  int buildSegTreeRec(int low, int high, int p, vector<int>& A) {
    if (low == high) {
      tree[p] = A[low];
      return tree[p];
    }
    int mid = (low + high) / 2;
    tree[p] = buildSegTreeRec(low, mid, leftChild(p), A) +
              buildSegTreeRec(mid + 1, high, rightChild(p), A);
    return tree[p];
  }

 public:
  int getSum(int x, int y) {
    if (x < 0 || ENDINDEX < y) return -INT_MAX;
    return getSumRec(STARTINDEX, ENDINDEX, x, y, 0);
  }

 public:
  int getSumRec(int low, int high, int x, int y, int p) {
    if (x <= low && high <= y) return tree[p];
    if (y < low || high < x) return 0;
    int mid = (low + high) / 2;
    return getSumRec(low, mid, x, y, leftChild(p)) +
           getSumRec(mid + 1, high, x, y, rightChild(p));
  }

 public:
  void addValue(int pos, int val) {
    addValueRec(STARTINDEX, ENDINDEX, pos, val, 0);
  }

 public:
  void set_remove(int pos, int val) {
    addValueRec(STARTINDEX, ENDINDEX, pos,
                max(val, tree[pos + (maxSize + 1) / 2]), 0);
  }

 public:
  void remove_index(int index) { remove_index_rec(0, index + 1); }

 public:
  void remove_index_rec(int index, int sum) {
    if (leftChild(index) >= maxSize) {
      addValue(index - (maxSize + 1) / 2 + 1, -1);
      return;
    }
    if (tree[leftChild(index)] < sum)
      remove_index_rec(rightChild(index), sum - tree[leftChild(index)]);
    else
      remove_index_rec(leftChild(index), sum);
  }

 public:
  void addValueRec(int low, int high, int pos, int val, int p) {
    if (low <= pos && pos <= high) {
      tree[p] = tree[p] + val;
      if (low != high) {
        int mid = (low + high) / 2;
        addValueRec(low, mid, pos, val, leftChild(p));
        addValueRec(mid + 1, high, pos, val, rightChild(p));
      }
    }
  }

 public:
  void print() { print_vector(tree); }

 public:
  void print_set() {
    int a = 0;
    for (int i = (0); i < (tree.size()); ++i)
      if (i >= maxSize / 2 && tree[i] != 0) {
        for (int j = (0); j < (tree[i]); ++j) {
          a = 1;
          cout << i - maxSize / 2 << " ";
        }
      }
    if (a == 1)
      cout << '\n';
    else
      cout << 0 << '\n';
  }

 public:
  void print_any() {
    int a = 0;
    for (int i = (0); i < (tree.size()); ++i)
      if (i >= maxSize / 2 && tree[i] != 0) {
        for (int j = (0); j < (tree[i]); ++j) {
          cout << i - maxSize / 2 << " ";
          return;
        }
      }
    cout << 0 << '\n';
  }
};
class max_tree {
  vector<int> tree;
  int counts = 0;
  int height;
  int maxSize;
  int STARTINDEX = 0;
  int ENDINDEX;

 public:
  max_tree(int n) {
    height = (int)ceilingOf(log2(n));
    maxSize = (1 << (height + 1)) - 1;
    tree.resize(maxSize);
    ENDINDEX = (1 << height) - 1;
  }

 public:
  int leftChild(int k) { return 2 * k + 1; }

 public:
  int rightChild(int k) { return 2 * k + 2; }

 public:
  void build_max_tree(vector<int>& A) {
    A.resize(1 << height, 0);
    buildSegTreeRec(STARTINDEX, ENDINDEX, 0, A);
  }

 public:
  int buildSegTreeRec(int low, int high, int p, vector<int>& A) {
    if (low == high) {
      tree[p] = A[low];
      return tree[p];
    }
    int mid = (low + high) / 2;
    tree[p] = max(buildSegTreeRec(low, mid, leftChild(p), A),
                  buildSegTreeRec(mid + 1, high, rightChild(p), A));
    return tree[p];
  }

 public:
  int get_max(int x, int y) {
    if (x < 0 || ENDINDEX < y) return -INT_MAX;
    return get_max1(STARTINDEX, ENDINDEX, x, y, 0);
  }

 public:
  int get_max1(int low, int high, int x, int y, int p) {
    if (x <= low && high <= y) return tree[p];
    if (y < low || high < x) return 0;
    int mid = (low + high) / 2;
    return max(get_max1(low, mid, x, y, leftChild(p)),
               get_max1(mid + 1, high, x, y, rightChild(p)));
    ;
  }

 public:
  void addValue(int pos, int val) {
    addValueRec(STARTINDEX, ENDINDEX, pos, val, 0);
  }

 public:
  void addValueRec(int low, int high, int pos, int val, int p) {
    if (low <= pos && pos <= high) {
      tree[p] = tree[p] + val;
      if (low != high) {
        int mid = (low + high) / 2;
        addValueRec(low, mid, pos, val, leftChild(p));
        addValueRec(mid + 1, high, pos, val, rightChild(p));
      }
    }
  }

 public:
  void print() { print_vector(tree); }
};
class FenwickTree {
 private:
  vector<int> ft;

 public:
  FenwickTree(int n) { ft.assign(n + 1, 0); }
  int rsq(int b) {
    int sum = 0;
    for (; b; b -= b & (-b)) sum += ft[b];
    return sum;
  }
  int rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); }
  void adjust(int k, int v) {
    for (; k < (int)ft.size(); k += k &= (-k)) ft[k] += v;
  }
  void print() { print_vector(ft); }
};
struct Graph {
  int V, E;
  vector<pair<int, pair<int, int>>> edges;
  Graph(int a, int b) {
    V = a;
    E = b;
  }
  void addEdge(int a, int b, int w) { edges.push_back({w, {a, b}}); }
  vector<int> links, sizes;
  int find(int a) {
    if (a == links[a]) return a;
    return links[a] = find(links[a]);
  }
  bool same(int a, int b) { return find(a) == find(b); }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (sizes[a] < sizes[b]) swap(a, b);
    sizes[a] += sizes[b];
    links[b] = a;
  }
  void sort_edges() { sort(edges.begin(), edges.end()); }
  long long kruskalMST() {
    sort_edges();
    links.resize(V);
    sizes.resize(V);
    for (int i = 0; i < V; i++) {
      links[i] = i;
      sizes[i] = 1;
    }
    long long sum = 0;
    int count = 0;
    for (int i = (0); i < (E); ++i) {
      int start = edges[i].second.first;
      int end = edges[i].second.second;
      if (!same(start, end)) {
        unite(start, end);
        sum += edges[i].first;
        count++;
      }
    }
    if (count != V - 1) return -1000000007;
    return sum;
  }
};
int modInverse(int a, int m) {
  int m0 = m;
  int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    int q = a / m;
    int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long power(long long number, int power, int mod) {
  long long ans = 1;
  while (number) {
    if (((number - 1) & 1) == 0) {
      ans *= power;
      ans %= mod;
      ans *= ans;
      ans %= mod;
      number--;
      number <<= 1;
    } else {
      ans *= ans;
      ans %= mod;
      number <<= 1;
    }
  }
  return ans;
}
long long a, b, c;
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
int main() {
  init();
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> positions;
  positions.resize(n);
  for (int i = (0); i < (n); ++i) positions[i].resize(n);
  vector<vector<char>> types;
  types.resize(n);
  for (int i = (0); i < (n); ++i) types[i].resize(n, ' ');
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      cin >> a >> b;
      if (a != -1) {
        positions[i][j] = {--a, --b};
        types[a][b] = 'X';
      } else {
        positions[i][j] = {-1, -1};
      }
    }
  }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j)
      if (types[i][j] == 'X' &&
          (positions[i][j].first != i || positions[i][j].second != j)) {
        cout << "INVALID" << '\n';
        return 0;
      }
  list<pair<int, int>> todo;
  vector<vector<int>> visited;
  visited.resize(n);
  for (int i = (0); i < (n); ++i) visited[i].resize(n);
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j)
      if (types[i][j] == 'X') todo.push_back({i, j});
  while (!todo.empty()) {
    pair<int, int> temp = todo.back();
    todo.pop_back();
    visited[temp.first][temp.second] = 1;
    if (temp.first > 0) {
      if (positions[temp.first][temp.second] ==
              positions[temp.first - 1][temp.second] &&
          !visited[temp.first - 1][temp.second]) {
        todo.push_back({temp.first - 1, temp.second});
        visited[temp.first - 1][temp.second] = 1;
        types[temp.first - 1][temp.second] = 'D';
      }
    }
    if (temp.first < n - 1) {
      if (positions[temp.first][temp.second] ==
              positions[temp.first + 1][temp.second] &&
          !visited[temp.first + 1][temp.second]) {
        todo.push_back({temp.first + 1, temp.second});
        visited[temp.first + 1][temp.second] = 1;
        types[temp.first + 1][temp.second] = 'U';
      }
    }
    if (temp.second > 0) {
      if (positions[temp.first][temp.second] ==
              positions[temp.first][temp.second - 1] &&
          !visited[temp.first][temp.second - 1]) {
        todo.push_back({temp.first, temp.second - 1});
        visited[temp.first][temp.second - 1] = 1;
        types[temp.first][temp.second - 1] = 'R';
      }
    }
    if (temp.second < n - 1) {
      if (positions[temp.first][temp.second] ==
              positions[temp.first][temp.second + 1] &&
          !visited[temp.first][temp.second + 1]) {
        todo.push_back({temp.first, temp.second + 1});
        visited[temp.first][temp.second + 1] = 1;
        types[temp.first][temp.second + 1] = 'L';
      }
    }
  }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j)
      if (!visited[i][j] &&
          (positions[i][j].first != -1 || positions[i][j].second != -1)) {
        cout << "INVALID" << '\n';
        return 0;
      }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j)
      if (!visited[i][j]) todo.push_back({i, j});
  while (!todo.empty()) {
    pair<int, int> temp = todo.back();
    todo.pop_back();
    if (visited[temp.first][temp.second]) continue;
    if (temp.first > 0) {
      if (positions[temp.first][temp.second] ==
          positions[temp.first - 1][temp.second]) {
        visited[temp.first][temp.second] = 1;
        visited[temp.first - 1][temp.second] = 1;
        types[temp.first][temp.second] = 'U';
        types[temp.first - 1][temp.second] = 'D';
      }
    }
    if (temp.first < n - 1) {
      if (positions[temp.first][temp.second] ==
          positions[temp.first + 1][temp.second]) {
        visited[temp.first][temp.second] = 1;
        visited[temp.first + 1][temp.second] = 1;
        types[temp.first][temp.second] = 'D';
        types[temp.first + 1][temp.second] = 'U';
      }
    }
    if (temp.second > 0) {
      if (positions[temp.first][temp.second] ==
          positions[temp.first][temp.second - 1]) {
        visited[temp.first][temp.second] = 1;
        visited[temp.first][temp.second - 1] = 1;
        types[temp.first][temp.second] = 'L';
        types[temp.first][temp.second - 1] = 'R';
      }
    }
    if (temp.second < n - 1) {
      if (positions[temp.first][temp.second] ==
          positions[temp.first][temp.second + 1]) {
        visited[temp.first][temp.second] = 1;
        visited[temp.first][temp.second + 1] = 1;
        types[temp.first][temp.second] = 'R';
        types[temp.first][temp.second + 1] = 'L';
      }
    }
  }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j)
      if (visited[i][j] == 0) {
        cout << "INVALID" << '\n';
        return 0;
      }
  cout << "VALID" << '\n';
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) cout << types[i][j];
    cout << '\n';
  }
}