/**
I'm employing the very fabric of the universe here!
*/
#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define bit(idx) idx&(-idx)
#define pll pair<ll, ll>
using namespace std;
const ll MAXN = 1e3 + 5;
ll n;
pll A[MAXN][MAXN];
char S[MAXN][MAXN];
void print(){
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++){
cout << S[i][j] << " ";
} cout << endl;
}
}
void rec1(ll bx, ll by, ll nx, ll ny){
if(nx - 1 > 0 && A[nx - 1][ny].fr == bx && A[nx - 1][ny].sc == by && S[nx - 1][ny] == '#'){
S[nx - 1][ny] = 'D';
rec1(bx, by, nx - 1, ny);
}
if(nx + 1 < n + 1 && A[nx + 1][ny].fr == bx && A[nx + 1][ny].sc == by && S[nx + 1][ny] == '#'){
S[nx + 1][ny] = 'U';
rec1(bx, by, nx + 1, ny);
}
if(ny - 1 > 0 && A[nx][ny - 1].fr == bx && A[nx][ny - 1].sc == by && S[nx][ny - 1] == '#'){
S[nx][ny - 1] = 'R';
rec1(bx, by, nx, ny - 1);
}
if(ny + 1 < n + 1 && A[nx][ny + 1].fr == bx && A[nx][ny + 1].sc == by && S[nx][ny + 1] == '#'){
S[nx][ny + 1] = 'L';
rec1(bx, by, nx, ny + 1);
}
}
bool ok(int x, int y){
if(x - 1 > 0 && A[x - 1][y].fr == -1 && A[x - 1][y].sc == -1 && S[x - 1][y] == '#'){
S[x][y] = 'U';
S[x - 1][y] = 'D';
return true;
}
if(x + 1 < n + 1 && A[x + 1][y].fr == -1 && A[x + 1][y].sc == -1 && S[x + 1][y] == '#'){
S[x][y] = 'D';
S[x + 1][y] = 'U';
return true;
}
if(y - 1 > 0 && A[x][y - 1].fr == -1 && A[x][y - 1].sc == -1 && S[x][y - 1] == '#'){
S[x][y] = 'L';
S[x][y - 1] = 'R';
return true;
}
if(y + 1 < n + 1 && A[x][y + 1].fr == -1 && A[x][y + 1].sc == -1 && S[x][y + 1] == '#'){
S[x][y] = 'R';
S[x][y + 1] = 'L';
return true;
}
return false;
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie();
cin >> n;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++){
ll x, y; cin >> x >> y;
A[i][j] = {x, y};
if(x == i && y == j){
S[i][j] = 'X';
}
else{
S[i][j] = '#';
}
}
}
print();
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++){
if(S[i][j] == 'X'){
rec1(i, j, i, j);
}
}
}
print();
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++){
if(A[i][j].fr == -1 && A[i][j].sc == -1 && S[i][j] == '#'){
if(ok(i, j) == false){
cout << " INVALID\n";
return 0;
}
}
}
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++){
if(S[i][j] == '#'){
cout << "INVALID\n";
return 0;
}
}
}
cout << "VALID\n";
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++){
cout << S[i][j];
} cout << endl;
}
}
/**
2
1 1 1 1
2 2 2 2
VALID
XL
RX
---------
3
-1 -1 -1 -1 -1 -1
-1 -1 2 2 -1 -1
-1 -1 -1 -1 -1 -1
VALID
RRD
UXD
ULL
*/
LyoqCkknbSBlbXBsb3lpbmcgdGhlIHZlcnkgZmFicmljIG9mIHRoZSB1bml2ZXJzZSBoZXJlIQoqLwojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIGVuZGwgJ1xuJwojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIGZyIGZpcnN0CiNkZWZpbmUgc2Mgc2Vjb25kCiNkZWZpbmUgbGwgbG9uZyBsb25nIGludAojZGVmaW5lIGJpdChpZHgpIGlkeCYoLWlkeCkKI2RlZmluZSBwbGwgcGFpcjxsbCwgbGw+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBsbCBNQVhOID0gMWUzICsgNTsKCmxsIG47CnBsbCBBW01BWE5dW01BWE5dOwpjaG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