import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Solution implements Runnable
{
    static class pair implements Comparable
    {
        int f;
        int s;
        pair(int fi, int se)
        {
            f=fi;
            s=se;
        }
        public int compareTo(Object o)//desc order
        {
            pair pr=(pair)o;
            if(s>pr.s)
                return -1;
            if(s==pr.s)
            {
                if(f>pr.f)
                    return 1;
                else
                    return -1;
            }
            else
                return 1;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            if(o!=null)
            {
                if((ob.f==this.f)&&(ob.s==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
    }
    public class triplet implements Comparable
    {
        int f;
        int s;
        int t;
        triplet(int f,int s,int t)
        {
            this.f=f;
            this.s=s;
            this.t=t;
        }
        public boolean equals(Object o)
        {
            triplet ob=(triplet)o;
            if(o!=null)
            {
                if((ob.f==this.f)&&(ob.s==this.s)&&(ob.t==this.t))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s+" "+this.t).hashCode();
        }
        public int compareTo(Object o)//asc order
        {
            triplet tr=(triplet)o;
            if(t>tr.t)
                return 1;
            else
                return -1;
        }
    }
    void merge1(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int [n1];
        int R[] = new int [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i]<=R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    void sort1(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort1(arr, l, m);
            sort1(arr , m+1, r);
            merge1(arr, l, m, r);
        }
    }
    pair a[][];
    int vis[][];
    char ans[][];
    int n,k=0;
    void dfs(int i,int j,int x,int y)
    {
        vis[i][j]=1;
        k++;
        if(i+1<=n && vis[i+1][j]==0 && a[i+1][j].f==x && a[i][j+1].s==y)
        {
            dfs(i+1,j,x,y);
            ans[i+1][j]='U';
        }
        if(j+1<=n && vis[i][j+1]==0 && a[i][j+1].f==x && a[i][j+1].s==y)
        {
            dfs(i,j+1,x,y);
            ans[i][j+1]='L';
        }
        if(i-1>=1 && vis[i-1][j]==0 && a[i-1][j].f==x && a[i-1][j].s==y)
        {
            dfs(i-1,j,x,y);
            ans[i-1][j]='D';
        }
        if(j-1>=1 && vis[i][j-1]==0 && a[i][j-1].f==x && a[i][j-1].s==y)
        {
            dfs(i,j-1,x,y);
            ans[i][j-1]='R';
        }
    }
    boolean ddffss(int i,int j)
    {
        vis[i][j]=1;
        if(i-1>=1 && a[i-1][j].f==-1 && a[i-1][j].s==-1)
        {
            ans[i][j]='U';
            return true;
        }
        if(j-1>=1 && a[i][j-1].f==-1 && a[i][j-1].s==-1)
        {
            ans[i][j]='L';
            return true;
        }
        if(i+1<=n && a[i+1][j].f==-1 && a[i+1][j].s==-1)
        {
            vis[i+1][j]=1;
            ans[i][j]='D';
            ans[i+1][j]='U';
            return true;
        }
        if(j+1<=n && a[i][j+1].f==-1 && a[i][j+1].s==-1)
        {
            vis[i][j+1]=1;
            ans[i][j]='R';
            ans[i][j+1]='L';
            return true;
        }
        return false;
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new Solution(),"Solution",1<<27).start();
    }
    public void run()
    {
        try
        {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            n=in.ni();
            vis=new int[n+1][n+1];
            ans=new char[n+1][n+1];
            a=new pair[n+1][n+1];
            HashMap<pair,Integer>hm=new HashMap<>();
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    int x=in.ni();
                    int y=in.ni();
                    pair p=new pair(x,y);
                    int kk=0;
                    if(hm.containsKey(p))
                        kk=hm.get(p);
                    hm.put(p,kk+1);
                    a[i][j]=new pair(x,y);
                }
            }
            int kk=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(a[i][j].f==i && a[i][j].s==j)
                    {
                        ans[i][j]='X';
                        k=0;
                        dfs(i,j,i,j);
                        pair p=new pair(i,j);
                        if(k!=hm.get(p))
                        {
                            kk=1;
                            break;
                        }
                    }
                }
            }
            if(kk==1)
            {
                out.println("INVALID");
            }
            else
            {
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=n;j++)
                    {
                        if(vis[i][j]==0)
                        {
                            boolean b=ddffss(i,j);
                            if(!b)
                            {
                                kk=1;
                                break;
                            }
                        }
                    }
                }
                if(kk==1)
                    out.println("INVALID");
                else
                {
                    out.println("VALID");
                    for(int i=1;i<=n;i++)
                    {
                        for(int j=1;j<=n;j++)
                            out.print(ans[i][j]);
                        out.println();
                    }
                }
            }
            out.close();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Solution implements Runnable
{
    static class pair implements Comparable
    {
        int f;
        int s;
        pair(int fi, int se)
        {
            f=fi;
            s=se;
        }
        public int compareTo(Object o)//desc order
        {
            pair pr=(pair)o;
            if(s>pr.s)
                return -1;
            if(s==pr.s)
            {
                if(f>pr.f)
                    return 1;
                else
                    return -1;
            }
            else
                return 1;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            if(o!=null)
            {
                if((ob.f==this.f)&&(ob.s==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
    }
    public class triplet implements Comparable
    {
        int f;
        int s;
        int t;
        triplet(int f,int s,int t)
        {
            this.f=f;
            this.s=s;
            this.t=t;
        }
        public boolean equals(Object o)
        {
            triplet ob=(triplet)o;
            if(o!=null)
            {
                if((ob.f==this.f)&&(ob.s==this.s)&&(ob.t==this.t))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s+" "+this.t).hashCode();
        }
        public int compareTo(Object o)//asc order
        {
            triplet tr=(triplet)o;
            if(t>tr.t)
                return 1;
            else
                return -1;
        }
    }
    void merge1(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int [n1];
        int R[] = new int [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i]<=R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    void sort1(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort1(arr, l, m);
            sort1(arr , m+1, r);
            merge1(arr, l, m, r);
        }
    }
    pair a[][];
    int vis[][];
    char ans[][];
    int n,k=0;
    void dfs(int i,int j,int x,int y)
    {
        vis[i][j]=1;
        k++;
        if(i+1<=n && vis[i+1][j]==0 && a[i+1][j].f==x && a[i+1][j].s==y)
        {
            dfs(i+1,j,x,y);
            ans[i+1][j]='U';
        }
        if(j+1<=n && vis[i][j+1]==0 && a[i][j+1].f==x && a[i][j+1].s==y)
        {
            dfs(i,j+1,x,y);
            ans[i][j+1]='L';
        }
        if(i-1>=1 && vis[i-1][j]==0 && a[i-1][j].f==x && a[i-1][j].s==y)
        {
            dfs(i-1,j,x,y);
            ans[i-1][j]='D';
        }
        if(j-1>=1 && vis[i][j-1]==0 && a[i][j-1].f==x && a[i][j-1].s==y)
        {
            dfs(i,j-1,x,y);
            ans[i][j-1]='R';
        }
    }
    boolean ddffss(int i,int j)
    {
        vis[i][j]=1;
        if(i-1>=1 && a[i-1][j].f==-1 && a[i-1][j].s==-1)
        {
            ans[i][j]='U';
            return true;
        }
        if(j-1>=1 && a[i][j-1].f==-1 && a[i][j-1].s==-1)
        {
            ans[i][j]='L';
            return true;
        }
        if(i+1<=n && a[i+1][j].f==-1 && a[i+1][j].s==-1)
        {
            vis[i+1][j]=1;
            ans[i][j]='D';
            ans[i+1][j]='U';
            return true;
        }
        if(j+1<=n && a[i][j+1].f==-1 && a[i][j+1].s==-1)
        {
            vis[i][j+1]=1;
            ans[i][j]='R';
            ans[i][j+1]='L';
            return true;
        }
        return false;
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new Solution(),"Solution",1<<27).start();
    }
    public void run()
    {
        try
        {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            n=in.ni();
            vis=new int[n+1][n+1];
            ans=new char[n+1][n+1];
            a=new pair[n+1][n+1];
            HashMap<pair,Integer>hm=new HashMap<>();
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    int x=in.ni();
                    int y=in.ni();
                    pair p=new pair(x,y);
                    int kk=0;
                    if(hm.containsKey(p))
                        kk=hm.get(p);
                    hm.put(p,kk+1);
                    a[i][j]=new pair(x,y);
                }
            }
            int kk=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(a[i][j].f==i && a[i][j].s==j)
                    {
                        ans[i][j]='X';
                        k=0;
                        dfs(i,j,i,j);
                        pair p=new pair(i,j);
                        if(k!=hm.get(p))
                        {
                            kk=1;
                            break;
                        }
                    }
                }
            }
            //System.out.println("hiii");
            if(kk==1)
            {
                out.println("INVALID");
            }
            else
            {
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=n;j++)
                    {
                        if(vis[i][j]==0)
                        {
                            boolean b=ddffss(i,j);
                            if(!b)
                            {
                                kk=1;
                                break;
                            }
                        }
                    }
                }
                if(kk==1)
                    out.println("INVALID");
                else
                {
                    out.println("VALID");
                    for(int i=1;i<=n;i++)
                    {
                        for(int j=1;j<=n;j++)
                            out.print(ans[i][j]);
                        out.println();
                    }
                }
            }
            out.close();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Solution implements Runnable
{
    static class pair implements Comparable
    {
        int f;
        int s;
        pair(int fi, int se)
        {
            f=fi;
            s=se;
        }
        public int compareTo(Object o)//desc order
        {
            pair pr=(pair)o;
            if(s>pr.s)
                return -1;
            if(s==pr.s)
            {
                if(f>pr.f)
                    return 1;
                else
                    return -1;
            }
            else
                return 1;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            if(o!=null)
            {
                if((ob.f==this.f)&&(ob.s==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
    }
    public class triplet implements Comparable
    {
        int f;
        int s;
        int t;
        triplet(int f,int s,int t)
        {
            this.f=f;
            this.s=s;
            this.t=t;
        }
        public boolean equals(Object o)
        {
            triplet ob=(triplet)o;
            if(o!=null)
            {
                if((ob.f==this.f)&&(ob.s==this.s)&&(ob.t==this.t))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s+" "+this.t).hashCode();
        }
        public int compareTo(Object o)//asc order
        {
            triplet tr=(triplet)o;
            if(t>tr.t)
                return 1;
            else
                return -1;
        }
    }
    void merge1(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int [n1];
        int R[] = new int [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i]<=R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    void sort1(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort1(arr, l, m);
            sort1(arr , m+1, r);
            merge1(arr, l, m, r);
        }
    }
    pair a[][];
    int vis[][];
    char ans[][];
    int n,k=0;
    void dfs(int i,int j,int x,int y)
    {
        vis[i][j]=1;
        k++;
        if(i+1<=n && vis[i+1][j]==0 && a[i+1][j].f==x && a[i+1][j].s==y)
        {
            dfs(i+1,j,x,y);
            ans[i+1][j]='U';
        }
        if(j+1<=n && vis[i][j+1]==0 && a[i][j+1].f==x && a[i][j+1].s==y)
        {
            dfs(i,j+1,x,y);
            ans[i][j+1]='L';
        }
        if(i-1>=1 && vis[i-1][j]==0 && a[i-1][j].f==x && a[i-1][j].s==y)
        {
            dfs(i-1,j,x,y);
            ans[i-1][j]='D';
        }
        if(j-1>=1 && vis[i][j-1]==0 && a[i][j-1].f==x && a[i][j-1].s==y)
        {
            dfs(i,j-1,x,y);
            ans[i][j-1]='R';
        }
    }
    boolean ddffss(int i,int j)
    {
        vis[i][j]=1;
        if(i-1>=1 && a[i-1][j].f==-1 && a[i-1][j].s==-1)
        {
            ans[i][j]='U';
            return true;
        }
        if(j-1>=1 && a[i][j-1].f==-1 && a[i][j-1].s==-1)
        {
            ans[i][j]='L';
            return true;
        }
        if(i+1<=n && a[i+1][j].f==-1 && a[i+1][j].s==-1)
        {
            vis[i+1][j]=1;
            ans[i][j]='D';
            ans[i+1][j]='U';
            return true;
        }
        if(j+1<=n && a[i][j+1].f==-1 && a[i][j+1].s==-1)
        {
            vis[i][j+1]=1;
            ans[i][j]='R';
            ans[i][j+1]='L';
            return true;
        }
        return false;
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new Solution(),"Solution",1<<27).start();
    }
    public void run()
    {
        try
        {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            n=in.ni();
            vis=new int[n+1][n+1];
            ans=new char[n+1][n+1];
            a=new pair[n+1][n+1];
            HashMap<pair,Integer>hm=new HashMap<>();
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    int x=in.ni();
                    int y=in.ni();
                    pair p=new pair(x,y);
                    int kk=0;
                    if(hm.containsKey(p))
                        kk=hm.get(p);
                    hm.put(p,kk+1);
                    a[i][j]=new pair(x,y);
                }
            }
            int kk=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(a[i][j].f==i && a[i][j].s==j)
                    {
                        ans[i][j]='X';
                        k=0;
                        dfs(i,j,i,j);
                        pair p=new pair(i,j);
                        if(k!=hm.get(p))
                        {
                            kk=1;
                            break;
                        }
                    }
                }
            }
            //System.out.println("hiii");
            if(kk==1)
            {
                out.println("INVALID");
            }
            else
            {
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=n;j++)
                    {
                        if(vis[i][j]==0 && a[i][j].f!=-1 && a[i][j].s!=-1)
                        {
                            kk=1;
                            break;
                        }
                    }
                }
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=n;j++)
                    {
                        if(vis[i][j]==0)
                        {
                            boolean b=ddffss(i,j);
                            if(!b)
                            {
                                kk=1;
                                break;
                            }
                        }
                    }
                }
                if(kk==1)
                    out.println("INVALID");
                else
                {
                    out.println("VALID");
                    for(int i=1;i<=n;i++)
                    {
                        for(int j=1;j<=n;j++)
                            out.print(ans[i][j]);
                        out.println();
                    }
                }
            }
            out.close();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.io.*;
import java.util.*;

public class Main {
	static final int[] dx = { 1, 0, -1, 0 };
	static final int[] dy = { 0, 1, 0, -1 };
	static final char[] dir = { 'U', 'L', 'D', 'R' };
	static int N;
	static int[][] X, Y;
	static char[][] grid;

	public static void bfs(int x, int y) {
		Queue<Integer> q = new LinkedList<>();
		q.offer(x * N + y);
		while (!q.isEmpty()) {
			int cur = q.poll();
			x = cur / N;
			y = cur % N;
			for (int i = 0; i < 4; i++) {
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (nx == -1 || nx == N || ny == -1 || ny == N || X[x][y] != X[nx][ny] || Y[x][y] != Y[nx][ny]
						|| grid[nx][ny] != 0) {
					continue;
				}
				grid[nx][ny] = dir[i];
				q.offer(nx * N + ny);
			}
		}
	}

	public static void main(String[] args) {
		InputReader in = new InputReader();
		StringBuilder out = new StringBuilder();

		N = in.nextInt();
		X = new int[N][N];
		Y = new int[N][N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				X[i][j] = in.nextInt() - 1;
				Y[i][j] = in.nextInt() - 1;
			}
		}
		grid = new char[N][N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (X[i][j] == i && Y[i][j] == j) {
					grid[i][j] = 'X';
					bfs(i, j);
				}
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (X[i][j] == -2 && Y[i][j] == -2 && grid[i][j] == 0) {
					for (int k = 0; k < 4; k++) {
						int nx = i + dx[k];
						int ny = j + dy[k];
						if (nx == -1 || nx == N || ny == -1 || ny == N || X[nx][ny] != -2 || Y[nx][ny] != -2) {
							continue;
						}
						grid[i][j] = dir[(k + 2) % 4];
						if (grid[nx][ny] == 0) {
							grid[nx][ny] = dir[k];
						}
						break;
					}
				}
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (grid[i][j] == 0) {
					System.out.println("INVALID");
					return;
				}
			}
		}
		out.append("VALID\n");
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				out.append(grid[i][j]);
			}
			out.append("\n");
		}

		System.out.print(out);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer st;

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


// Magic. Do not touch.

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }
    public static int includedCount=0;
    public static void main(String[] args) throws IOException {

        FastReader fr=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);

        /*
inputCopy
2
1 1 1 1
2 2 2 2
outputCopy
VALID
XL
RX
inputCopy
3
-1 -1 -1 -1 -1 -1
-1 -1 2 2 -1 -1
-1 -1 -1 -1 -1 -1
outputCopy
VALID
RRD
UXD
ULL

3
2 2 2 2 2 2
2 2 2 2 2 2
2 2 2 2 2 2

3
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
         */
        int t=1;

        for(int ti=0;ti<t;++ti)
        {
            int n=fr.i();
            Node [][] arr=new Node[n][n];
            Queue<Node> queue=new LinkedList<>();
            for(int i=0;i<n;++i)
            {
                for(int j=0;j<n;++j)
                {
                    int endX=fr.i()-1;
                    int endY=fr.i()-1;
                    if(endX==-2 && endY==-2)
                    {
                        endX=-1;
                        endY=-1;
                    }
                    arr[i][j]=new Node(i,j,false,endX,endY);
                    if(arr[i][j].included)
                        queue.add(arr[i][j]);
                }
            }
            for(Node endNode:queue)
            {
                Queue<Node> queue2=new LinkedList<>();
                queue2.add(endNode);
                while(!queue2.isEmpty())
                {
                    Node newNode=queue2.poll();
                    //up
                    if(newNode.x>0)
                    {
                        Node upper = arr[newNode.x - 1][newNode.y];
                        if(upper.endX==endNode.x && upper.endY==endNode.y && !upper.included)
                        {
                            queue2.add(upper);
                            upper.included=true;
                            upper.direction='D';
                            ++includedCount;
                        }
                    }
                    //down
                    if(newNode.x<n-1)
                    {
                        Node below = arr[newNode.x + 1][newNode.y];
                        if(below.endX==endNode.x && below.endY==endNode.y && !below.included)
                        {
                            queue2.add(below);
                            below.included=true;
                            below.direction='U';
                            ++includedCount;
                        }
                    }
                    //left
                    if(newNode.y>0)
                    {
                        Node left = arr[newNode.x][newNode.y-1];
                        if(left.endX==endNode.x && left.endY==endNode.y && !left.included)
                        {
                            queue2.add(left);
                            left.included=true;
                            left.direction='R';
                            ++includedCount;
                        }
                    }
                    //right
                    if(newNode.y<n-1)
                    {
                        Node right = arr[newNode.x][newNode.y+1];
                        if(right.endX==endNode.x && right.endY==endNode.y && !right.included)
                        {
                            queue2.add(right);
                            right.included=true;
                            right.direction='L';
                            ++includedCount;
                        }
                    }
                }
            }
            for(int i=0;i<n;++i)
            {
                for(int j=0;j<n;++j)
                {
                    if(!arr[i][j].included)
                    {
                        if(arr[i][j].endX==-1 && arr[i][j].endY==-1)
                        {
                            Node startNode=arr[i][j];
                            boolean isCyclic=isCyclic(arr,startNode,n);
                        }
                    }
                }
            }
            if(includedCount!=n*n)
            {
                pw.println("INVALID");
                System.err.println(includedCount);
                pw.flush();
                return;
            }
            pw.println("VALID");
            for(int i=0;i<n;++i)
            {
                for(int j=0;j<n;++j)
                    pw.print(arr[i][j].direction);
                pw.println();
            }
        }
        pw.flush();
        pw.close();
    }
    public static boolean isCyclic(Node [][] arr,Node startNode,int n)
    {
        if(startNode.endX!=-1 || startNode.endY!=-1)
            return false;
        if(startNode.included)
            return true;
        startNode.included=true;
        //up
        if(startNode.x>0)
        {
            Node upper=arr[startNode.x-1][startNode.y];
            if(isCyclic(arr,upper,n))
            {
                startNode.direction='U';
                ++includedCount;
                return true;
            }
        }
        //down
        if(startNode.x<n-1)
        {
            Node down=arr[startNode.x+1][startNode.y];
            if(isCyclic(arr,down,n))
            {
                startNode.direction='D';
                ++includedCount;
                return true;
            }
        }
        //left
        if(startNode.y>0)
        {
            Node left=arr[startNode.x][startNode.y-1];
            if(isCyclic(arr,left,n))
            {
                startNode.direction='L';
                ++includedCount;
                return true;
            }
        }
        //right
        if(startNode.y<n-1)
        {
            Node right=arr[startNode.x][startNode.y+1];
            if(isCyclic(arr,right,n))
            {
                startNode.direction='R';
                ++includedCount;
                return true;
            }
        }
        return false;
    }
    static class Node
    {
        int x,y,endX,endY;
        boolean included;
        char direction;

        public Node(int x, int y, boolean included,int endX,int endY) {
            this.x = x;
            this.y = y;
            this.endX=endX;
            this.endY=endY;
            this.included = false;
            if(x==endX && y==endY)
            {
                direction = 'X';
                this.included=true;
                ++includedCount;
            }
        }
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
//const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

int n;
PI a[1111][1111];
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
char ans[1111][1111];
vector<PI>v;
#define mp make_pair
int vis[1111][1111];
PI pre[1111][1111];
bool ck(int x, int y){
    return x>=1&&x<=n&&y>=1&&y<=n;
}
int X,Y;
void gao(int x1, int y1, int x2, int y2){
    if(x1==x2){
        if(y2>y1){
            ans[x1][y1]='R';
        }
        else ans[x1][y1]='L';
    }
    else{
        if(x2>x1)ans[x1][y1]='D';
        else ans[x1][y1]='U';
    }
    //printf("ans[%d][%d]=%c\n",x1,y1,ans[x1][y1]);
}

vector<PI>o;
int ok;
stack<PI>s;
int ys[1111][1111];
int nx,ny;
void dfs(int x, int y, int fax, int fay){
    vis[x][y]=1;
    if(fax!=-1)gao(x,y,fax,fay);
    for(int i = 0; i < 4; i++){
        int tox = x+dx[i];
        int toy = y+dy[i];
        if(ck(tox,toy)&&!vis[tox][toy]&&a[tox][toy]==a[x][y])dfs(tox,toy,x,y);
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d %d", &a[i][j].fst, &a[i][j].sc);
            if(a[i][j].fst==i&&a[i][j].sc==j){
                ans[i][j]='X';
                v.pb(mp(i,j));
            }
            if(a[i][j].fst==-1){
                vis[i][j]=1;
                o.pb(mp(i,j));
            }
        }
    }
    for(int i = 0; i < (int)v.size(); i++){
        int x = v[i].fst, y = v[i].sc;
        if(!vis[x][y])dfs(x,y,-1,-1);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j].fst==-1)vis[i][j]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(vis[i][j])continue;
            //printf("%d %d\n",i,j);
            if(i>=1&&a[i][j]==a[i-1][j]){
                //printf("1\n");
                gao(i,j,i-1,j);gao(i-1,j,i,j);
                vis[i][j]=vis[i-1][j]=1;
                dfs(i,j,-1,-1);dfs(i-1,j,-1,-1);
            }
            else if(j>=1&&a[i][j]==a[i][j-1]){
                //printf("2\n");
                vis[i][j]=vis[i][j-1]=1;
                gao(i,j,i,j-1);gao(i,j-1,i,j);
                dfs(i,j,-1,-1);dfs(i,j-1,-1,-1);
            }
            else{
                if(a[i][j]!=a[i+1][j]&&a[i][j]!=a[i][j+1]){
                    return printf("INVALID"),0;
                }
            }
        }
    }

    printf("VALID\n");
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%c",ans[i][j]);
        }printf("\n");
    }
    return 0;
}

/*
5
1 1 -1 -1 1 3 1 4 1 5
2 1 -1 -1 -1 -1 2 4 2 5
3 1 -1 -1 -1 -1 3 4 3 5
-1 -1 -1 -1 4 3 4 4 4 5
5 1 -1 -1 5 3 5 4 5 5

5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
2 1 2 2 -1 -1 2 4 2 5
3 1 3 2 -1 -1 3 4 3 5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

5
1 1 1 2 1 3 1 4 1 5
-1 -1 -1 -1 2 3 -1 -1 -1 -1
-1 -1 -1 -1 3 3 -1 -1 -1 -1
4 1 4 2 4 3 4 4 4 5
5 1 5 2 5 3 5 4 5 5

2
1 1 1 1
1 1 1 1

 */


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
//const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

int n;
PI a[1111][1111];
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
char ans[1111][1111];
vector<PI>v;
#define mp make_pair
int vis[1111][1111];
PI pre[1111][1111];
bool ck(int x, int y){
    return x>=1&&x<=n&&y>=1&&y<=n;
}
int X,Y;
void gao(int x1, int y1, int x2, int y2){
    if(x1==x2){
        if(y2>y1){
            ans[x1][y1]='R';
        }
        else ans[x1][y1]='L';
    }
    else{
        if(x2>x1)ans[x1][y1]='D';
        else ans[x1][y1]='U';
    }
    //printf("ans[%d][%d]=%c\n",x1,y1,ans[x1][y1]);
}

vector<PI>o;
int ok;
stack<PI>s;
int ys[1111][1111];
int nx,ny;
void dfs(int x, int y, int fax, int fay){
    vis[x][y]=1;
    if(fax!=-1)gao(x,y,fax,fay);
    for(int i = 0; i < 4; i++){
        int tox = x+dx[i];
        int toy = y+dy[i];
        if(ck(tox,toy)&&!vis[tox][toy]&&a[tox][toy]==a[x][y])dfs(tox,toy,x,y);
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d %d", &a[i][j].fst, &a[i][j].sc);
            if(a[i][j].fst==i&&a[i][j].sc==j){
                ans[i][j]='X';
                v.pb(mp(i,j));
            }
            if(a[i][j].fst==-1){
                vis[i][j]=1;
                o.pb(mp(i,j));
            }
        }
    }
    for(int i = 0; i < (int)v.size(); i++){
        int x = v[i].fst, y = v[i].sc;
        if(!vis[x][y])dfs(x,y,-1,-1);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j].fst==-1)vis[i][j]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(vis[i][j])continue;
            //printf("%d %d\n",i,j);
            if(a[i][j]==a[i-1][j]){
                printf("1\n");
                gao(i,j,i-1,j);gao(i-1,j,i,j);
                vis[i][j]=vis[i-1][j]=1;
                dfs(i,j,-1,-1);dfs(i-1,j,-1,-1);
            }
            else if(a[i][j]==a[i][j-1]){
                printf("2\n");
                vis[i][j]=vis[i][j-1]=1;
                gao(i,j,i,j-1);gao(i,j-1,i,j);
                dfs(i,j,-1,-1);dfs(i,j-1,-1,-1);
            }
            else{
                if(a[i][j]!=a[i+1][j]&&a[i][j]!=a[i][j+1]){
                    return printf("INVALID"),0;
                }
            }
        }
    }

    printf("VALID\n");
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%c",ans[i][j]);
        }printf("\n");
    }
    return 0;
}

/*
5
1 1 -1 -1 1 3 1 4 1 5
2 1 -1 -1 -1 -1 2 4 2 5
3 1 -1 -1 -1 -1 3 4 3 5
-1 -1 -1 -1 4 3 4 4 4 5
5 1 -1 -1 5 3 5 4 5 5

5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
2 1 2 2 -1 -1 2 4 2 5
3 1 3 2 -1 -1 3 4 3 5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

5
1 1 1 2 1 3 1 4 1 5
-1 -1 -1 -1 2 3 -1 -1 -1 -1
-1 -1 -1 -1 3 3 -1 -1 -1 -1
4 1 4 2 4 3 4 4 4 5
5 1 5 2 5 3 5 4 5 5

2
1 1 1 1
1 1 1 1

 */


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
//const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

int n;
PI a[1111][1111];
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
char ans[1111][1111];
vector<PI>v;
#define mp make_pair
int vis[1111][1111];
PI pre[1111][1111];
bool ck(int x, int y){
    return x>=1&&x<=n&&y>=1&&y<=n;
}
int X,Y;
void gao(int x1, int y1, int x2, int y2){
    if(x1==x2){
        if(y2>y1){
            ans[x1][y1]='R';
        }
        else ans[x1][y1]='L';
    }
    else{
        if(x2>x1)ans[x1][y1]='D';
        else ans[x1][y1]='U';
    }
    //printf("ans[%d][%d]=%c\n",x1,y1,ans[x1][y1]);
}
void dfs(int x, int y, int fax, int fay){
    vis[x][y]=1;
    if(fax!=-1)gao(x,y,fax,fay);
    for(int i = 0; i < 4; i++){
        int tox = x+dx[i];
        int toy = y+dy[i];
        if(ck(tox,toy)&&!vis[tox][toy]&&a[tox][toy].fst==X&&a[tox][toy].sc==Y){
            dfs(tox,toy,x,y);
        }
    }
}
vector<PI>o;
int ok;
stack<PI>s;
int ys[1111][1111];
int nx,ny;
void f(int x, int y, int fax, int fay){
    //printf("f:%d %d %d %d\n",x,y,fax,fay);
    if(ok)return;
    pre[x][y]=mp(fax,fay);
    vis[x][y]=1;
    for(int i = 0; i < 4; i++){
        int tox = x+dx[i];
        int toy = y+dy[i];
        if(ck(tox,toy)&&!(tox==fax&&toy==fay)){
            //printf("(%d %d) = %d\n",tox,toy,vis[tox][toy]);
            if(vis[tox][toy]==1){
                nx=tox;ny=toy;
                //printf("! (%d %d)= %d\n",tox,toy,vis[tox][toy]);
                ok=1;return;
            }
            else if(vis[tox][toy]==0){
                //printf("!\n");
                ys[tox][toy]=1;
                s.push(mp(tox,toy));
                //printf("  go:%d %d\n",tox,toy);
                f(tox,toy,x,y);
                if(ok)return;
                s.pop();
                ys[tox][toy]=0;
            }
        }
    }
}
void g(int x, int y, int fax, int fay){
    if(fax!=-1)gao(x,y,fax,fay);
    ys[x][y]=1;
    for(int i = 0; i<4; i++){
        int tox=x+dx[i];
        int toy=y+dy[i];
        if(ck(tox,toy)&&a[tox][toy].fst==-1&&!ys[tox][toy]){
            g(tox,toy,x,y);
        }
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d %d", &a[i][j].fst, &a[i][j].sc);
            if(a[i][j].fst==i&&a[i][j].sc==j){
                ans[i][j]='X';
                v.pb(mp(i,j));
            }
            if(a[i][j].fst==-1){
                vis[i][j]=1;
                o.pb(mp(i,j));
            }
        }
    }
    /*
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%c",ans[i][j]);
        }printf("\n");
    }*/
    for(int i = 0; i < (int)v.size(); i++){
        X=v[i].fst,Y=v[i].sc;
        dfs(X,Y,-1,-1);
    }
    //printf("===%c===\n",ans[2][2]);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            vis[i][j]=0;
            if(a[i][j].fst!=-1)vis[i][j]=2;
        }
    }
    for(int i = 0; i < (int)o.size(); i++){
        X=o[i].fst;Y=o[i].sc;
        //printf("X:%d Y:%d\n",X,Y);
        if(!vis[X][Y]){
            ok=0;
            s.push(mp(X,Y));
            f(X,Y,-1,-1);
            if(!ok)return printf("INVALID"),0;
            else{
                X=s.top().fst;
                Y=s.top().sc;
                //printf("x:%d y:%d\n",X,Y);
                s.pop();
                int hv=0;
                vector<PI>tmp;
                tmp.pb(mp(X,Y));
                PI lst = mp(X,Y);
                while(!s.empty()){
                    int x = s.top().fst;
                    int y = s.top().sc;
                    //printf("x:%d y:%d\n",x,y);
                    //g(x,y,-1,-1);
                    s.pop();
                    if(!hv)gao(lst.fst,lst.sc,x,y);
                    if(!hv)tmp.pb(mp(x,y));
                    else ys[x][y]=0;
                    lst=mp(x,y);
                    if(x==nx&&y==ny){
                        hv=1;
                        gao(nx,ny,X,Y);
                        //printf("%d %d %d %d\n",nx,ny,X,Y);
                    }
                }
                for(int k = 0; k < (int)tmp.size(); k++){
                    //printf("tog:%d %d\n",tmp[k].fst,tmp[k].sc);
                    g(tmp[k].fst,tmp[k].sc,-1,-1);

                }
            }
        }
    }
    printf("VALID\n");
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%c",ans[i][j]);
        }printf("\n");
    }
    return 0;
}

/*
5
1 1 -1 -1 1 3 1 4 1 5
2 1 -1 -1 -1 -1 2 4 2 5
3 1 -1 -1 -1 -1 3 4 3 5
-1 -1 -1 -1 4 3 4 4 4 5
5 1 -1 -1 5 3 5 4 5 5
 */


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
//const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

int n;
PI a[1111][1111];
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
char ans[1111][1111];
vector<PI>v;
#define mp make_pair
int vis[1111][1111];
PI pre[1111][1111];
bool ck(int x, int y){
    return x>=1&&x<=n&&y>=1&&y<=n;
}
int X,Y;
void gao(int x1, int y1, int x2, int y2){
    if(x1==x2){
        if(y2>y1){
            ans[x1][y1]='R';
        }
        else ans[x1][y1]='L';
    }
    else{
        if(x2>x1)ans[x1][y1]='D';
        else ans[x1][y1]='U';
    }
    //printf("ans[%d][%d]=%c\n",x1,y1,ans[x1][y1]);
}

vector<PI>o;
int ok;
stack<PI>s;
int ys[1111][1111];
int nx,ny;
void dfs(int x, int y, int fax, int fay){
    vis[x][y]=1;
    if(fax!=-1)gao(x,y,fax,fay);
    for(int i = 0; i < 4; i++){
        int tox = x+dx[i];
        int toy = y+dy[i];
        if(ck(tox,toy)&&!vis[tox][toy]&&a[tox][toy]==a[x][y])dfs(tox,toy,x,y);
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d %d", &a[i][j].fst, &a[i][j].sc);
            if(a[i][j].fst==i&&a[i][j].sc==j){
                ans[i][j]='X';
                v.pb(mp(i,j));
            }
            if(a[i][j].fst==-1){
                vis[i][j]=1;
                o.pb(mp(i,j));
            }
        }
    }
    for(int i = 0; i < (int)v.size(); i++){
        int x = v[i].fst, y = v[i].sc;
        if(!vis[x][y])dfs(x,y,-1,-1);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j].fst==-1)vis[i][j]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(vis[i][j])continue;
            if(a[i][j]==a[i-1][j]){
                gao(i,j,i-1,j);gao(i-1,j,i,j);
                dfs(i,j,-1,-1);dfs(i-1,j,-1,-1);
            }
            else if(a[i][j]==a[i][j-1]){
                gao(i,j,i,j-1);gao(i,j-1,i,j);
                dfs(i,j,-1,-1);dfs(i,j-1,-1,-1);
            }
            else{
                if(a[i][j]!=a[i+1][j]&&a[i][j]!=a[i][j+1]){
                    return printf("INVALID"),0;
                }
            }
        }
    }

    printf("VALID\n");
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%c",ans[i][j]);
        }printf("\n");
    }
    return 0;
}

/*
5
1 1 -1 -1 1 3 1 4 1 5
2 1 -1 -1 -1 -1 2 4 2 5
3 1 -1 -1 -1 -1 3 4 3 5
-1 -1 -1 -1 4 3 4 4 4 5
5 1 -1 -1 5 3 5 4 5 5

5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
2 1 2 2 -1 -1 2 4 2 5
3 1 3 2 -1 -1 3 4 3 5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

5
1 1 1 2 1 3 1 4 1 5
-1 -1 -1 -1 2 3 -1 -1 -1 -1
-1 -1 -1 -1 3 3 -1 -1 -1 -1
4 1 4 2 4 3 4 4 4 5
5 1 5 2 5 3 5 4 5 5

2
1 1 1 1
1 1 1 1

 */


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
//const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

int n;
PI a[1111][1111];
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
char ans[1111][1111];
vector<PI>v;
#define mp make_pair
int vis[1111][1111];
PI pre[1111][1111];
bool ck(int x, int y){
    return x>=1&&x<=n&&y>=1&&y<=n;
}
int X,Y;
void gao(int x1, int y1, int x2, int y2){
    if(x1==x2){
        if(y2>y1){
            ans[x1][y1]='R';
        }
        else ans[x1][y1]='L';
    }
    else{
        if(x2>x1)ans[x1][y1]='D';
        else ans[x1][y1]='U';
    }
    //printf("ans[%d][%d]=%c\n",x1,y1,ans[x1][y1]);
}

vector<PI>o;
int ok;
stack<PI>s;
int ys[1111][1111];
int nx,ny;
void dfs(int x, int y, int fax, int fay){
    vis[x][y]=1;
    if(fax!=-1)gao(x,y,fax,fay);
    for(int i = 0; i < 4; i++){
        int tox = x+dx[i];
        int toy = y+dy[i];
        if(ck(tox,toy)&&!vis[tox][toy]&&a[tox][toy]==a[x][y])dfs(tox,toy,x,y);
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d %d", &a[i][j].fst, &a[i][j].sc);
            if(a[i][j].fst==i&&a[i][j].sc==j){
                ans[i][j]='X';
                v.pb(mp(i,j));
            }
            if(a[i][j].fst==-1){
                vis[i][j]=1;
                o.pb(mp(i,j));
            }
        }
    }
    for(int i = 0; i < (int)v.size(); i++){
        int x = v[i].fst, y = v[i].sc;
        if(!vis[x][y])dfs(x,y,-1,-1);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j].fst==-1)vis[i][j]=0;
            else {
                if(!vis[i][j])return printf("INVALID"),0;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(vis[i][j])continue;
            //printf("%d %d\n",i,j);
            if(i>=1&&a[i][j]==a[i-1][j]){
                //printf("1\n");
                gao(i,j,i-1,j);gao(i-1,j,i,j);
                vis[i][j]=vis[i-1][j]=1;
                dfs(i,j,-1,-1);dfs(i-1,j,-1,-1);
            }
            else if(j>=1&&a[i][j]==a[i][j-1]){
                //printf("2\n");
                vis[i][j]=vis[i][j-1]=1;
                gao(i,j,i,j-1);gao(i,j-1,i,j);
                dfs(i,j,-1,-1);dfs(i,j-1,-1,-1);
            }
            else{
                if(a[i][j]!=a[i+1][j]&&a[i][j]!=a[i][j+1]){
                    return printf("INVALID"),0;
                }
            }
        }
    }

    printf("VALID\n");
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%c",ans[i][j]);
        }printf("\n");
    }
    return 0;
}

/*
5
1 1 -1 -1 1 3 1 4 1 5
2 1 -1 -1 -1 -1 2 4 2 5
3 1 -1 -1 -1 -1 3 4 3 5
-1 -1 -1 -1 4 3 4 4 4 5
5 1 -1 -1 5 3 5 4 5 5

5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
2 1 2 2 -1 -1 2 4 2 5
3 1 3 2 -1 -1 3 4 3 5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

5
1 1 1 2 1 3 1 4 1 5
-1 -1 -1 -1 2 3 -1 -1 -1 -1
-1 -1 -1 -1 3 3 -1 -1 -1 -1
4 1 4 2 4 3 4 4 4 5
5 1 5 2 5 3 5 4 5 5

2
1 1 1 1
1 1 1 1

 */


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
//const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

int n;
PI a[1111][1111];
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
char ans[1111][1111];
vector<PI>v;
#define mp make_pair
int vis[1111][1111];
PI pre[1111][1111];
bool ck(int x, int y){
    return x>=1&&x<=n&&y>=1&&y<=n;
}
int X,Y;
void gao(int x1, int y1, int x2, int y2){
    if(x1==x2){
        if(y2>y1){
            ans[x1][y1]='R';
        }
        else ans[x1][y1]='L';
    }
    else{
        if(x2>x1)ans[x1][y1]='D';
        else ans[x1][y1]='U';
    }
    //printf("ans[%d][%d]=%c\n",x1,y1,ans[x1][y1]);
}

vector<PI>o;
int ok;
stack<PI>s;
int ys[1111][1111];
int nx,ny;
void dfs(int x, int y, int fax, int fay){
    vis[x][y]=1;
    if(fax!=-1)gao(x,y,fax,fay);
    for(int i = 0; i < 4; i++){
        int tox = x+dx[i];
        int toy = y+dy[i];
        if(ck(tox,toy)&&!vis[tox][toy]&&a[tox][toy]==a[x][y])dfs(tox,toy,x,y);
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d %d", &a[i][j].fst, &a[i][j].sc);
            if(a[i][j].fst==i&&a[i][j].sc==j){
                ans[i][j]='X';
                v.pb(mp(i,j));
            }
            if(a[i][j].fst==-1){
                vis[i][j]=1;
                o.pb(mp(i,j));
            }
        }
    }
    for(int i = 0; i < (int)v.size(); i++){
        int x = v[i].fst, y = v[i].sc;
        if(!vis[x][y])dfs(x,y,-1,-1);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j].fst==-1)vis[i][j]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(vis[i][j])continue;
            //printf("%d %d\n",i,j);
            if(a[i][j]==a[i-1][j]){
                //printf("1\n");
                gao(i,j,i-1,j);gao(i-1,j,i,j);
                vis[i][j]=vis[i-1][j]=1;
                dfs(i,j,-1,-1);dfs(i-1,j,-1,-1);
            }
            else if(a[i][j]==a[i][j-1]){
                //printf("2\n");
                vis[i][j]=vis[i][j-1]=1;
                gao(i,j,i,j-1);gao(i,j-1,i,j);
                dfs(i,j,-1,-1);dfs(i,j-1,-1,-1);
            }
            else{
                if(a[i][j]!=a[i+1][j]&&a[i][j]!=a[i][j+1]){
                    return printf("INVALID"),0;
                }
            }
        }
    }

    printf("VALID\n");
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%c",ans[i][j]);
        }printf("\n");
    }
    return 0;
}

/*
5
1 1 -1 -1 1 3 1 4 1 5
2 1 -1 -1 -1 -1 2 4 2 5
3 1 -1 -1 -1 -1 3 4 3 5
-1 -1 -1 -1 4 3 4 4 4 5
5 1 -1 -1 5 3 5 4 5 5

5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
2 1 2 2 -1 -1 2 4 2 5
3 1 3 2 -1 -1 3 4 3 5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

5
1 1 1 2 1 3 1 4 1 5
-1 -1 -1 -1 2 3 -1 -1 -1 -1
-1 -1 -1 -1 3 3 -1 -1 -1 -1
4 1 4 2 4 3 4 4 4 5
5 1 5 2 5 3 5 4 5 5

2
1 1 1 1
1 1 1 1

 */


#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
pi A[1005][1005];
char ans[1005][1005];
vector<pi> V[1005][1005];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
char ch[5] = {'D','L','U','R','X'};
int cnt,n;

void bfs(int sy, int sx) {
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if (ny <= 0 || ny > n || nx <= 0 || nx > n) continue;
			if (A[ny][nx] == A[y][x]&&ans[ny][nx]=='.') {
				++cnt;
				ans[ny][nx] = ch[k];
				q.push({ny,nx});
				break;
			}
		}
	}
}

void go(int ex, int ey, int sx, int sy){
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		if(y==ey&&x==ex)continue;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if(ny<=0||ny>n||nx<=0||nx>n)continue;
			if(A[ny][nx]==A[y][x]) {
				++cnt;
				if(k==0) {
					ans[y][x] = 'U';
				} else if(k==1) {
					ans[y][x] = 'R';
				} else if (k==2) {
					ans[y][x] = 'D';
				} else {
					ans[y][x] = 'L';
				}
				if(ans[ny][nx]=='.')q.push({ny,nx});
				break;
			}
		}
	}
}

int32_t main() {
	IAMSPEED
	cin >> n;
	FOR(i,1,n) {
		FOR(j,1,n) {
			ans[i][j]='.';
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			int a,b; cin >> a >> b;
			if(a==-1){
				++a,++b;
			}
			A[i][j] = {a, b};
			V[a][b].pb({i,j});

		}
	}
	FOR(i,1,n) {
		FOR(j,1,n){
			if(A[i][j]==pi(i,j)) {
				ans[i][j] = 'X';
				++cnt;
				bfs(i,j);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(A[i][j] == pi(0,0)) {
				bfs(i,j);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(ans[i][j]=='.')go(A[i][j].f, A[i][j].s,i,j);
		}
	}
	bool can = 1;
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(ans[i][j]=='.')can=0;
		}
	}
	if(!can) return cout << "INVALID",0;
	cout << "VALID\n";
	FOR(i,1,n) {
		FOR(j,1,n) {
			cout<<ans[i][j];
		}
		cout<<'\n';
	}
}


#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
pi A[1005][1005];
char ans[1005][1005];
vector<pi> V[1005][1005];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
char ch[5] = {'D','L','U','R','X'};
int cnt,n;

void bfs(int sy, int sx) {
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if (ny <= 0 || ny > n || nx <= 0 || nx > n) continue;
			if (A[ny][nx] == A[y][x]&&ans[ny][nx]=='.') {
				++cnt;
				ans[ny][nx] = ch[k];
				q.push({ny,nx});
			}
		}
	}
}

int32_t main() {
	IAMSPEED
	cin >> n;
	FOR(i,1,n) {
		FOR(j,1,n) {
			ans[i][j]='.';
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			int a,b; cin >> a >> b;
			if(a==-1){
				++a,++b;
			}
			A[i][j] = {a, b};
			V[a][b].pb({i,j});

		}
	}
	FOR(i,1,n) {
		FOR(j,1,n){
			if(A[i][j]==pi(i,j)) {
				ans[i][j] = 'X';
				++cnt;
				bfs(i,j);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(A[i][j] == pi(0,0)) {
				bfs(i,j);
			}
		}
	}
	bool can = 1;
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(ans[i][j]=='.')can=0;
		}
	}
	if(!can) return cout << "INVALID",0;
	cout << "VALID\n";
	FOR(i,1,n) {
		FOR(j,1,n) {
			cout<<ans[i][j];
		}
		cout<<'\n';
	}
}


#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
pi A[1005][1005];
char ans[1005][1005];
vector<pi> V[1005][1005];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
char ch[5] = {'D','L','U','R','X'};
int cnt,n;

void bfs(int sy, int sx) {
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if (ny <= 0 || ny > n || nx <= 0 || nx > n) continue;
			if (A[ny][nx] == A[y][x]&&ans[ny][nx]=='.') {
				++cnt;
				ans[ny][nx] = ch[k];
				q.push({ny,nx});
			}
		}
	}
}

void go(int ex, int ey, int sx, int sy){
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		if(y==ey&&x==ex)continue;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if(ny<=0||ny>n||nx<=0||nx>n)continue;
			if(A[ny][nx]==A[y][x]) {
				++cnt;
				if(k==0) {
					ans[y][x] = 'U';
				} else if(k==1) {
					ans[y][x] = 'R';
				} else if (k==2) {
					ans[y][x] = 'D';
				} else {
					ans[y][x] = 'L';
				}
				if(ans[ny][nx]=='.')q.push({ny,nx});
				break;
			}
		}
	}
}

int32_t main() {
	IAMSPEED
	cin >> n;
	FOR(i,1,n) {
		FOR(j,1,n) {
			ans[i][j]='.';
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			int a,b; cin >> a >> b;
			if(a==-1){
				++a,++b;
			}
			A[i][j] = {a, b};
			V[a][b].pb({i,j});

		}
	}
	FOR(i,1,n) {
		FOR(j,1,n){
			if(A[i][j]==pi(i,j)) {
				ans[i][j] = 'X';
				++cnt;
				bfs(i,j);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(A[i][j] == pi(0,0)) {
				bfs(i,j);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(ans[i][j]=='.')go(A[i][j].f, A[i][j].s,i,j);
		}
	}
	bool can = 1;
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(ans[i][j]=='.')can=0;
		}
	}
	if(!can) return cout << "INVALID",0;
	cout << "VALID\n";
	FOR(i,1,n) {
		FOR(j,1,n) {
			cout<<ans[i][j];
		}
		cout<<'\n';
	}
}


#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
pi A[1005][1005];
char ans[1005][1005];
vector<pi> V[1005][1005];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
char ch[5] = {'D','L','U','R','X'};
int cnt,n;

void bfs(int sy, int sx) {
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if (ny <= 0 || ny > n || nx <= 0 || nx > n) continue;
			if (A[ny][nx] == A[y][x]&&ans[ny][nx]=='.') {
				++cnt;
				ans[ny][nx] = ch[k];
				q.push({ny,nx});
			}
		}
	}
}

void go(int ex, int ey, int sx, int sy){
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		if(y==ey&&x==ex)continue;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if(ny<=0||ny>n||nx<=0||nx>n)continue;
			if(A[ny][nx]==A[y][x]) {
				++cnt;
				if(k==0) {
					ans[y][x] = 'U';
				} else if(k==1) {
					ans[y][x] = 'R';
				} else if (k==2) {
					ans[y][x] = 'D';
				} else {
					ans[y][x] = 'L';
				}
				if(ans[ny][nx]=='.')q.push({ny,nx});
				break;
			}
		}
	}
}

int32_t main() {
	IAMSPEED
	cin >> n;
	FOR(i,1,n) {
		FOR(j,1,n) {
			ans[i][j]='.';
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			int a,b; cin >> a >> b;
			if(a==-1){
				++a,++b;
			}
			A[i][j] = {a, b};
			V[a][b].pb({i,j});

		}
	}
	FOR(i,1,n) {
		FOR(j,1,n){
			if(A[i][j]==pi(i,j)) {
				ans[i][j] = 'X';
				++cnt;
				bfs(i,j);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(A[i][j] == pi(0,0)) {
				bfs(i,j);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(ans[i][j]=='.')go(A[i][j].f, A[i][j].s,i,j);
		}
	}
	db(cnt);
	//~ if(cnt!=n*n) return cout << "INVALID",0;
	cout << "VALID\n";
	FOR(i,1,n) {
		FOR(j,1,n) {
			cout<<ans[i][j];
		}
		cout<<'\n';
	}
}


    #include <bits/stdc++.h>
    #include <bits/extc++.h>
    using namespace __gnu_pbds;
    using namespace std;
    #define testing 1
    #define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
    #define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
    #define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
    #define db(x) cerr << #x << "=" << x << endl
    #define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
    #define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
    #define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
    #define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
    #define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    #define ll long long
    #define pb push_back
    #define inf (int)1e9+500
    #define oo (ll)1e18+500
    #define all(x) (x).begin(), (x).end()
    #define f first
    #define s second
    #define reach cerr << "LINE: " << __LINE__ << "\n";
    typedef pair <int, int> pi;
    typedef pair <ll,ll> pl;
    typedef pair <pi, int> pii;
    typedef tuple<int,int,int> ti3;
    string cts(char x) {string t(1,x); return t;}
    ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
    const int MOD = 1e9 + 7;
    template <typename T> void chmax(T& a, T b) {
    	a = max(a, b);
    }
    template <typename T> void chmin(T& a, T b) {
    	a = min(a, b);
    }
    #define MAXN
    #if !testing
    #define cerr if(0)cout
    #endif
    pi A[1005][1005];
    char ans[1005][1005];
    vector<pi> V[1005][1005];
    int dy[4] = {-1,0,1,0};
    int dx[4] = {0,1,0,-1};
    char ch[5] = {'D','L','U','R','X'};
    int cnt,n;

    void bfs(int sy, int sx) {
    	queue<pi> q;
    	for(q.push({sy,sx});q.size();q.pop()) {
    		int y = q.front().f, x = q.front().s;
    		FOR(k,0,3) {
    			int ny = y + dy[k], nx = x + dx[k];
    			if (ny <= 0 || ny > n || nx <= 0 || nx > n) continue;
    			if (A[ny][nx] == A[y][x]&&ans[ny][nx]=='.') {
    				++cnt;
    				ans[ny][nx] = ch[k];
    				q.push({ny,nx});
    			}
    		}
    	}
    }

    void go(int ex, int ey, int sx, int sy){
    	queue<pi> q;
    	for(q.push({sy,sx});q.size();q.pop()) {
    		int y = q.front().f, x = q.front().s;
    		if(y==ey&&x==ex)continue;
    		FOR(k,0,3) {
    			int ny = y + dy[k], nx = x + dx[k];
    			if(ny<=0||ny>n||nx<=0||nx>n)continue;
    			if(A[ny][nx]==A[y][x]) {
    				++cnt;
    				if(k==0) {
    					ans[y][x] = 'U';
    				} else if(k==1) {
    					ans[y][x] = 'R';
    				} else if (k==2) {
    					ans[y][x] = 'D';
    				} else {
    					ans[y][x] = 'L';
    				}
    				if(ans[ny][nx]=='.')q.push({ny,nx});
    				break;
    			}
    		}
    	}
    }

    int32_t main() {
    	IAMSPEED
    	cin >> n;
    	FOR(i,1,n) {
    		FOR(j,1,n) {
    			ans[i][j]='.';
    		}
    	}
    	FOR(i,1,n) {
    		FOR(j,1,n) {
    			int a,b; cin >> a >> b;
    			if(a==-1){
    				++a,++b;
    			}
    			A[i][j] = {a, b};
    			V[a][b].pb({i,j});

    		}
    	}
    	FOR(i,1,n) {
    		FOR(j,1,n){
    			if(A[i][j]==pi(i,j)) {
    				ans[i][j] = 'X';
    				++cnt;
    				bfs(i,j);
    			}
    		}
    	}
    	FOR(i,1,n) {
    		FOR(j,1,n) {
    			if(A[i][j] == pi(0,0)) {
    				bfs(i,j);
    			}
    		}
    	}
    	FOR(i,1,n) {
    		FOR(j,1,n) {
    			if(ans[i][j]=='.')go(A[i][j].f, A[i][j].s,i,j);
    		}
    	}
    	db(cnt);
    	if(cnt!=n*n) return cout << "INVALID",0;
    	cout << "VALID\n";
    	FOR(i,1,n) {
    		FOR(j,1,n) {
    			cout<<ans[i][j];
    		}
    		cout<<'\n';
    	}
    }


#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
pi A[1005][1005], oA[1005][1005];
char ans[1005][1005];
vector<pi> V[1005][1005];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
char ch[5] = {'D','L','U','R','X'};
int cnt,n;
struct ufds_ {
	pi p[1005][1005];
	int sz[1005][1005];
	ufds_() {
		FOR(i,0,1004) {
			FOR(j,0,1004) {
				p[i][j] = {i, j};
				sz[i][j] = 1;
			}
		}
	}
	pi find(int x, int y) {
		if (p[x][y] == pi(x,y)) return {x,y};
		else return p[x][y] = find(p[x][y].first, p[x][y].second);
	}
	void merge(pi a, pi b) {
		a = find(a.first, a.second);
		b = find(b.first, b.second);
		if (sz[a.f][a.s]<sz[b.f][b.s]) swap(a,b);
		sz[a.first][a.second] += sz[b.first][b.second];
		p[b.first][b.second] = {a.first, a.second};
	}

} ufds;
void bfs(int sy, int sx, bool cycle) {
	queue<pi> q;
	for(q.push({sy,sx});q.size();q.pop()) {
		int y = q.front().f, x = q.front().s;
		FOR(k,0,3) {
			int ny = y + dy[k], nx = x + dx[k];
			if (ny <= 0 || ny > n || nx <= 0 || nx > n) continue;
			if (A[ny][nx] == A[y][x]&&ans[ny][nx]==0) {
				++cnt;
				ans[ny][nx] = ch[k];
				q.push({ny,nx});
				break;
			}
		}
	}
}

int32_t main() {
	IAMSPEED
	cin >> n;
	FOR(i,1,n) {
		FOR(j,1,n) {
			int a,b; cin >> a >> b;
			if(a==-1){
				++a,++b;
			}
			A[i][j] = {a, b};
			oA[i][j] = {a, b};
			V[a][b].pb({i,j});

		}
	}
	FOR(i,1,n) {
		FOR(j,1,n){
			if(A[i][j]==pi(i,j)) {
				ans[i][j] = 'X';
				++cnt;
				bfs(i,j,0);
			}
		}
	}
	FOR(i,1,n) {
		FOR(j,1,n) {
			if(A[i][j] == pi(0,0)) {
				bfs(i,j,1);

			}
		}
	}

	db(cnt);
	if(cnt!=n*n) return cout << "INVALID",0;
	cout << "VALID\n";
	FOR(i,1,n) {
		FOR(j,1,n) {
			cout<<ans[i][j];
		}
		cout<<'\n';
	}
}


//CodeCraft-20 (Div. 2)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

void taskA(){
    int t; cin >> t;
    while(t--) {
        int n,m; cin >> n >> m;
        vector<int> a(n);
        ll sum = 0;
        _for(i,0,n) cin >> a[i], sum+=a[i];
        cout << min(sum, (ll)m) << "\n";
    }
    return;
}
void taskB1(){
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        string s; cin >> s;
        string ans = s;
        int res = 1;
        _rep(k,2,n) {
            string ans_pre = s.substr(k-1, n);
            string ans_suf = s.substr(0, k-1);

            if(n%2 == k%2)
                reverse(ans_suf.begin(), ans_suf.end());
    // It can be observed that the suffix will be s1..sk−1 if n and k have the same parity and sk−1..s1 otherwise.
            ans_pre += ans_suf;
            if(ans > ans_pre) ans = ans_pre, res = k;
        }
        cout << ans << "\n" << res << "\n";
    }
    return;
}
void taskC(){
    int n,m,p; cin >> n >> m >> p;
    vector<ll> a(n), b(m), c(n+m-1, 0);
    _for(i,0,n) cin >> a[i], a[i] %= p;
    _for(i,0,m) cin >> b[i], b[i] %= p;
    int x = 0, y = 0;
    while(!a[x]) x++;
    while(!b[y]) y++;
    cout << x+y;
    return;
}

const int N = 1010;
int x[N][N], y[N][N];
char d[N][N];
bool connnect(int x1, int y1, int x2, int y2, char c1, char c2) {
    if(x[x2][y2] == -1) {
        d[x1][y1] = c1;
        if(d[x2][y2] == '\0') d[x2][y2] = c2;
        return true;
    } return false;
}
void dfs(int x1, int y1, char c1) {
    if(d[x1][y1] != '\0') return;

    d[x1][y1] = c1;
    if(x[x1][y1] == x[x1+1][y1] and y[x1+1][y1] == y[x1][y1])
        dfs(x1+1, y1, 'U');
    if(x[x1][y1] == x[x1-1][y1] and y[x1-1][y1] == y[x1][y1])
        dfs(x1-1, y1, 'D');
    if(x[x1][y1] == x[x1][y1-1] and y[x1][y1-1] == y[x1][y1])
        dfs(x1, y1-1, 'R');
    if(x[x1][y1] == x[x1][y1+1] and y[x1][y1+1] == y[x1][y1])
        dfs(x1, y1+1, 'L');
    return;
}
void taskD(){
    //int a1 = -1; cout << a1 << "  !a1 = " << !a1 << "  ~a1 = " << ~a1 << "\n";
    //a1 = 0;
     //cout << a1 << "  !a1 = " << !a1 << "  ~a1 = " << ~a1 << "\n";

    int n; cin >> n;
    _rep(i,1,n) _rep(j,1,n)  cin >> x[i][j] >> y[i][j];
    _rep(i,1,n) _rep(j,1,n) {
        if(x[i][j] == -1) {
            bool flag = (d[i][j] != '\0');
            if(!flag) flag = connnect(i, j, i+1, j, 'D', 'U');
            if(!flag) flag = connnect(i, j, i-1, j, 'U', 'D');
            if(!flag) flag = connnect(i, j, i, j+1, 'R', 'L');
            if(!flag) flag = connnect(i, j, i, j-1, 'L', 'R');
            if(!flag) {cout << "INVALID\n"; return;}
        } else if(x[i][j] == i and y[i][j] == j) dfs(i, j, 'X');
    }

    //_rep(i,1,n) { _rep(j,1,n) cout << d[i][j]; cout << "\n";} cout << "ennnnn\n";

    _rep(i,1,n) _rep(j,1,n)
        if(d[i][j] == '\0') {cout << "INVALID\n"; return;}
    cout << "VALID\n";
    _rep(i,1,n) { _rep(j,1,n) cout << d[i][j]; cout << "\n";}
    return;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    //taskA();
    //taskB1();
    //taskC();
    taskD();
    return 0;
}


//CodeCraft-20 (Div. 2)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

void taskA(){
    int t; cin >> t;
    while(t--) {
        int n,m; cin >> n >> m;
        vector<int> a(n);
        ll sum = 0;
        _for(i,0,n) cin >> a[i], sum+=a[i];
        cout << min(sum, (ll)m) << "\n";
    }
    return;
}
void taskB1(){
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        string s; cin >> s;
        string ans = s;
        int res = 1;
        _rep(k,2,n) {
            string ans_pre = s.substr(k-1, n);
            string ans_suf = s.substr(0, k-1);

            if(n%2 == k%2)
                reverse(ans_suf.begin(), ans_suf.end());
    // It can be observed that the suffix will be s1..sk−1 if n and k have the same parity and sk−1..s1 otherwise.
            ans_pre += ans_suf;
            if(ans > ans_pre) ans = ans_pre, res = k;
        }
        cout << ans << "\n" << res << "\n";
    }
    return;
}
void taskC(){
    int n,m,p; cin >> n >> m >> p;
    vector<ll> a(n), b(m), c(n+m-1, 0);
    _for(i,0,n) cin >> a[i], a[i] %= p;
    _for(i,0,m) cin >> b[i], b[i] %= p;
    int x = 0, y = 0;
    while(!a[x]) x++;
    while(!b[y]) y++;
    cout << x+y;
    return;
}

const int N = 1010;
int x[N][N], y[N][N];
char d[N][N];
bool connnect(int x1, int y1, int x2, int y2, char c1, char c2) {
    if(!x[x2][y2]) {
        d[x2][y2] = c2;
        if(d[x1][y1] == '\0') d[x1][y1] = c1;
        return true;
    } return false;
}
void dfs(int x1, int y1, char c1) {
    if(d[x1][y1] != '\0') return;
    d[x1][y1] = c1;
    if(x[x1][y1] == x[x1+1][y1] and y[x1+1][y1] == y[x1][y1])
        dfs(x1+1, y1, 'U');
    if(x[x1][y1] == x[x1-1][y1] and y[x1-1][y1] == y[x1][y1])
        dfs(x1-1, y1, 'D');
    if(x[x1][y1] == x[x1][y1-1] and y[x1][y1-1] == y[x1][y1])
        dfs(x1, y1-1, 'R');
    if(x[x1][y1] == x[x1][y1+1] and y[x1][y1+1] == y[x1][y1])
        dfs(x1, y1+1, 'L');
    return;
}
void taskD(){
    int n; cin >> n;
    _rep(i,1,n) _rep(j,1,n)  cin >> x[i][j] >> y[i][j];
    _rep(i,1,n) _rep(j,1,n) {
        if(!x[i][j]) {
            bool flag = false;
            if(!flag) flag = connnect(i, j, i+1, j, 'D', 'U');
            if(!flag) flag = connnect(i, j, i-1, j, 'U', 'D');
            if(!flag) flag = connnect(i, j, i, j+1, 'R', 'L');
            if(!flag) flag = connnect(i, j, i, j-1, 'L', 'R');
            if(!flag) {cout << "INVAILD\n"; return;}
        } else if(x[i][j] == i and y[i][j] == j) dfs(i, j, 'X');
    }
    int f = 0;
    _rep(i,1,n) _rep(j,1,n)
        if(d[i][j] == '\0') {cout << "INVAILD\n"; return;}
    cout << "VAILD\n";
    _rep(i,1,n) { _rep(j,1,n) cout << d[i][j]; cout << "\n";}
    return;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    //taskA();
    //taskB1();
    //taskC();
    taskD();
    return 0;
}


//CodeCraft-20 (Div. 2)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

void taskA(){
    int t; cin >> t;
    while(t--) {
        int n,m; cin >> n >> m;
        vector<int> a(n);
        ll sum = 0;
        _for(i,0,n) cin >> a[i], sum+=a[i];
        cout << min(sum, (ll)m) << "\n";
    }
    return;
}
void taskB1(){
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        string s; cin >> s;
        string ans = s;
        int res = 1;
        _rep(k,2,n) {
            string ans_pre = s.substr(k-1, n);
            string ans_suf = s.substr(0, k-1);

            if(n%2 == k%2)
                reverse(ans_suf.begin(), ans_suf.end());
    // It can be observed that the suffix will be s1..sk−1 if n and k have the same parity and sk−1..s1 otherwise.
            ans_pre += ans_suf;
            if(ans > ans_pre) ans = ans_pre, res = k;
        }
        cout << ans << "\n" << res << "\n";
    }
    return;
}
void taskC(){
    int n,m,p; cin >> n >> m >> p;
    vector<ll> a(n), b(m), c(n+m-1, 0);
    _for(i,0,n) cin >> a[i], a[i] %= p;
    _for(i,0,m) cin >> b[i], b[i] %= p;
    int x = 0, y = 0;
    while(!a[x]) x++;
    while(!b[y]) y++;
    cout << x+y;
    return;
}

const int N = 1010;
int x[N][N], y[N][N];
char d[N][N];
bool connnect(int x1, int y1, int x2, int y2, char c1, char c2) {
    if(!x[x2][y2]) {
        d[x2][y2] = c2;
        if(d[x1][y1] == '\0') d[x1][y1] = c1;
        return true;
    } return false;
}
void dfs(int x1, int y1, char c1) {
    if(d[x1][y1] != '\0') return;
    d[x1][y1] = c1;
    if(x[x1][y1] == x[x1+1][y1] and y[x1+1][y1] == y[x1][y1])
        dfs(x1+1, y1, 'U');
    if(x[x1][y1] == x[x1-1][y1] and y[x1-1][y1] == y[x1][y1])
        dfs(x1-1, y1, 'D');
    if(x[x1][y1] == x[x1][y1-1] and y[x1][y1-1] == y[x1][y1])
        dfs(x1, y1-1, 'R');
    if(x[x1][y1] == x[x1][y1+1] and y[x1][y1+1] == y[x1][y1])
        dfs(x1, y1+1, 'L');
    return;
}
void taskD(){
    int n; cin >> n;
    _rep(i,1,n) _rep(j,1,n)  cin >> x[i][j] >> y[i][j];
    _rep(i,1,n) _rep(j,1,n) {
        if(!x[i][j]) {
            bool flag = false;
            if(!flag) flag = connnect(i, j, i+1, j, 'D', 'U');
            if(!flag) flag = connnect(i, j, i-1, j, 'U', 'D');
            if(!flag) flag = connnect(i, j, i, j+1, 'R', 'L');
            if(!flag) flag = connnect(i, j, i, j-1, 'L', 'R');
            if(!flag) {cout << "INVALID\n"; return;}
        } else if(x[i][j] == i and y[i][j] == j) dfs(i, j, 'X');
    }
    int f = 0;
    _rep(i,1,n) _rep(j,1,n)
        if(d[i][j] == '\0') {cout << "INVALID\n"; return;}
    cout << "VALID\n";
    _rep(i,1,n) { _rep(j,1,n) cout << d[i][j]; cout << "\n";}
    return;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    //taskA();
    //taskB1();
    //taskC();
    taskD();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
using namespace std;

const int MAXN = 2010;

pair<int, int> g[MAXN][MAXN];
bool used[MAXN][MAXN];
char str[MAXN][MAXN];
int n;
bool isValid(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= n;}

void dfs(int x, int y) {
    queue<pair<int, int> > q;
    q.push({x, y});
    while (!q.empty()) {
        pair<int, int> tmp = q.front();
        q.pop();
        x = tmp.first;
        y = tmp.second;
        if (isValid(x-1, y) && !used[x-1][y] && g[x-1][y] == g[x][y]) {
            q.push({x-1, y});
            used[x-1][y] = true;
            str[x-1][y] = 'D';
        }
        if (isValid(x+1, y) && !used[x+1][y] && g[x+1][y] == g[x][y]) {
            q.push({x+1, y});
            used[x+1][y] = true;
            str[x+1][y] = 'U';
        }
        if (isValid(x, y+1) && !used[x][y+1] && g[x][y+1] == g[x][y]) {
            q.push({x, y+1});
            used[x][y+1] = true;
            str[x][y+1] = 'L';
        }
        if (isValid(x, y-1) && !used[x][y-1] && g[x][y-1] == g[x][y]) {
            q.push({x, y-1});
            used[x][y-1] = true;
            str[x][y-1] = 'R';
        }
    } return;
}

void bianli(int x, int y) {
    if (isValid(x-1, y) && g[x-1][y] == g[x][y] && !used[x-1][y]) {
        used[x][y] = true;  used[x-1][y] = true;
        str[x][y] = 'U';    str[x-1][y] = 'D';
        dfs(x, y);          dfs(x-1, y);
    } else if (isValid(x+1, y) && g[x+1][y] == g[x][y] && !used[x+1][y]) {
        used[x][y] = true;  used[x+1][y] = true;
        str[x][y] = 'D';    str[x+1][y] = 'U';
        dfs(x, y);          dfs(x+1, y);
    } else if (isValid(x, y+1) && g[x][y+1] == g[x][y] && !used[x][y+1]) {
        used[x][y] = true;  used[x][y+1] = true;
        str[x][y] = 'R';    str[x][y+1] = 'L';
        dfs(x, y);          dfs(x, y+1);
    } else if (isValid(x, y-1) && g[x][y-1] == g[x][y] && !used[x][y-1]) {
        used[x][y] = true;  used[x][y-1] = true;
        str[x][y] = 'L';    str[x][y-1] = 'R';
        dfs(x, y);          dfs(x, y-1);
    } return;
}

void taskD() {

    while (scanf("%d", &n) == 1) {
        _for(i,0,n) _for(j,0,n) {
                int x, y; cin >> x >> y;
                g[i+1][j+1] = {x, y};
            }
        memset(used, false, sizeof(used));

        _rep(i,1,n) _rep(j,1,n)
           if (!used[i][j] && g[i][j].first == -1) {
                    bianli(i, j);
                }

        _rep(i,1,n) _rep(j,1,n) {
                if (used[i][j]) continue;
                if (g[i][j].first == -1) continue;
                int xx = g[i][j].first;
                int yy = g[i][j].second;
                if (g[xx][yy].first != xx || g[xx][yy].second != yy) continue;
                if (!used[xx][yy]) {
                    used[xx][yy] = true;
                    str[xx][yy] = 'X';
                    dfs(xx, yy);
                }
            }
        bool flag = true;
        _rep(i,1,n) _rep(j,1,n) if (!used[i][j]) flag = false;

        if (!flag) cout << ("INVALID\n");
        else {
            cout << ("VALID\n");
            _rep(i,1,n) {
                str[i][n+1] = 0;
                cout << str[i] + 1 << "\n";
            }
        } break;
    }
    return;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    taskD();
    return 0;
}


//CodeCraft-20 (Div. 2)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

void taskA(){
    int t; cin >> t;
    while(t--) {
        int n,m; cin >> n >> m;
        vector<int> a(n);
        ll sum = 0;
        _for(i,0,n) cin >> a[i], sum+=a[i];
        cout << min(sum, (ll)m) << "\n";
    }
    return;
}
void taskB1(){
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        string s; cin >> s;
        string ans = s;
        int res = 1;
        _rep(k,2,n) {
            string ans_pre = s.substr(k-1, n);
            string ans_suf = s.substr(0, k-1);

            if(n%2 == k%2)
                reverse(ans_suf.begin(), ans_suf.end());
    // It can be observed that the suffix will be s1..sk−1 if n and k have the same parity and sk−1..s1 otherwise.
            ans_pre += ans_suf;
            if(ans > ans_pre) ans = ans_pre, res = k;
        }
        cout << ans << "\n" << res << "\n";
    }
    return;
}
void taskC(){
    int n,m,p; cin >> n >> m >> p;
    vector<ll> a(n), b(m), c(n+m-1, 0);
    _for(i,0,n) cin >> a[i], a[i] %= p;
    _for(i,0,m) cin >> b[i], b[i] %= p;
    int x = 0, y = 0;
    while(!a[x]) x++;
    while(!b[y]) y++;
    cout << x+y;
    return;
}

const int N = 1010;
int x[N][N], y[N][N], n;
char d[N][N];
bool connnect(int x1, int y1, int x2, int y2, char c1, char c2) {
    if(x2 < 1 or x2 > n or y2 < 1 or y2 > n) return false;
    if(x[x2][y2] == -1) {
        d[x1][y1] = c1;
        if(d[x2][y2] == '\0') d[x2][y2] = c2;
        return true;
    } return false;
}
void dfs(int x1, int y1, char c1) {
    if(x1 < 1 or x1 > n or y1 < 1 or y1 > n) return;
    if(d[x1][y1] != '\0') return;

    d[x1][y1] = c1;
    if(x[x1][y1] == x[x1+1][y1] and y[x1+1][y1] == y[x1][y1])
        dfs(x1+1, y1, 'U');
    if(x[x1][y1] == x[x1-1][y1] and y[x1-1][y1] == y[x1][y1])
        dfs(x1-1, y1, 'D');
    if(x[x1][y1] == x[x1][y1-1] and y[x1][y1-1] == y[x1][y1])
        dfs(x1, y1-1, 'R');
    if(x[x1][y1] == x[x1][y1+1] and y[x1][y1+1] == y[x1][y1])
        dfs(x1, y1+1, 'L');
    return;
}
void taskD(){
    //int a1 = -1; cout << a1 << "  !a1 = " << !a1 << "  ~a1 = " << ~a1 << "\n";
    //a1 = 0;
     //cout << a1 << "  !a1 = " << !a1 << "  ~a1 = " << ~a1 << "\n";

    cin >> n;
    _rep(i,1,n) _rep(j,1,n)  cin >> x[i][j] >> y[i][j];
    _rep(i,1,n) _rep(j,1,n) {
        if(x[i][j] == -1) {
            bool flag = (d[i][j] != '\0');
            if(!flag) flag = connnect(i, j, i+1, j, 'D', 'U');
            if(!flag) flag = connnect(i, j, i-1, j, 'U', 'D');
            if(!flag) flag = connnect(i, j, i, j+1, 'R', 'L');
            if(!flag) flag = connnect(i, j, i, j-1, 'L', 'R');
            if(!flag) {cout << "INVALID\n"; return;}
        } else if(x[i][j] == i and y[i][j] == j) dfs(i, j, 'X');
    }

    //_rep(i,1,n) { _rep(j,1,n) cout << d[i][j]; cout << "\n";} cout << "ennnnn\n";

    _rep(i,1,n) _rep(j,1,n)
        if(d[i][j] == '\0') {cout << "INVALID\n"; return;}
    cout << "VALID\n";
    _rep(i,1,n) { _rep(j,1,n) cout << d[i][j]; cout << "\n";}
    return;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    //taskA();
    //taskB1();
    //taskC();
    taskD();
    return 0;
}