<reponame>jaredliw/mcc-python-solutions
N = int(input())
board = []
for _ in range(N):
    board.append(list(input()))

for row in range(N):
    stop_flag = False
    for col in range(N):
        cur = board[row][col]
        flipped = "W" if cur == "B" else "B"
        left = flipped if col == 0 else board[row][col - 1]
        right = flipped if col == N - 1 else board[row][col + 1]
        up = flipped if row == 0 else board[row - 1][col]
        down = flipped if row == N - 1 else board[row + 1][col]
        if left == right == up == down and left != cur:
            print("INVALID")
            stop_flag = True
            break
    if stop_flag:
        break
else:
    print("VALID")

N = int(input())
board = []
for _ in range(N):
    board.append(list(input()))

for row in range(N):
    stop_flag = False
    for col in range(N):
        cur = board[row][col]
        flipped = "W" if cur == "B" else "B"
        left = flipped if col == 0 else board[row][col - 1]
        right = flipped if col == N - 1 else board[row][col + 1]
        up = flipped if row == 0 else board[row - 1][col]
        down = flipped if row == N - 1 else board[row + 1][col]
        if left == right == up == down and left != cur:
            print("INVALID")
            stop_flag = True
            break
    if stop_flag:
        break
else:
    print("VALID")