You are given a square map as a matrix of integer strings. Each cell of the map has a value denoting its depth. We will call a cell of the map a cavity if and only if this cell is not on the border of the map and each cell adjacent to it has strictly smaller depth. Two cells are adjacent if they have a common side, or edge.

Find all the cavities on the map and replace their depths with the uppercase character X.  

Example 

$grid=['989','191','111']$

The grid is rearranged for clarity:

989
191
111

Return:

989
1X1
111

The center cell was deeper than those on its edges: [8,1,1,1].  The deep cells in the top two corners do not share an edge with the center cell, and none of the border cells is eligible.  

Function Description  

Complete the cavityMap function in the editor below.   

cavityMap has the following parameter(s):  

string grid[n]: each string represents a row of the grid  

Returns  

string{n}: the modified grid

Input Format

The first line contains an integer $n$, the number of rows and columns in the grid.  

Each of the following $n$ lines (rows) contains $n$ positive digits without spaces (columns) that represent the depth at $grid[row,column]$.  

Constraints

$1\leq n\leq100$

Sample Input
STDIN   Function
-----   --------
4       grid[] size n = 4
1112    grid = ['1112', '1912', '1892', '1234']
1912
1892
1234

Sample Output
1112
1X12
18X2
1234

Explanation

The two cells with the depth of 9 are not on the border and are surrounded on all sides by shallower cells.  Their values are replaced by X.

Difficulty: EASY

Solutions:
n = int(input())
maplist = []
for i in range(n):
	maplist.append(list(input()))
for i in range(1, n - 1):
	for j in range(1, n - 1):
		c = maplist[i][j]
		t = maplist[i - 1][j]
		l = maplist[i][j - 1]
		r = maplist[i][j + 1]
		b = maplist[i + 1][j]
		if c > t and c > l and (c > r) and (c > b):
			maplist[i][j] = 'X'
for i in range(n):
	print(''.join(maplist[i]))


def find_all_cavits(arr):
	result = []
	left = lambda x, y: (x, y - 1)
	right = lambda x, y: (x, y + 1)
	top = lambda x, y: (x - 1, y)
	bottom = lambda x, y: (x + 1, y)
	neighborhood = [left, right, top, bottom]
	for (index_i, i) in enumerate(arr):
		result.append([])
		for (index_j, j) in enumerate(i):
			is_cavit = True
			for f in neighborhood:
				(ii, jj) = f(index_i, index_j)
				if not (0 <= ii < len(arr) and 0 <= jj < len(arr[0]) and (arr[ii][jj] < j)):
					is_cavit = False
					break
			result[index_i].append('X' if is_cavit else j)
	return [''.join(map(str, i)) for i in result]

def main():
	arr = []
	n = int(input())
	for i in range(1, n + 1):
		arr.append([int(j) for j in input()])
	for line in find_all_cavits(arr):
		print(line)
main()


import sys
line = sys.stdin.readline()
n = int(line)
tmp = []
output = []
for i in range(n):
	line = sys.stdin.readline()
	line = line.strip()
	column = [char for char in line]
	tmp.append(list(map(int, column)))
	output.append(column[:])
for x in range(1, n - 1):
	for y in range(1, n - 1):
		val = tmp[x][y]
		if tmp[x][y - 1] < val and tmp[x - 1][y] < val and (tmp[x][y + 1] < val) and (tmp[x + 1][y] < val):
			output[x][y] = 'X'
for i in range(n):
	print(''.join(output[i]))


n = int(input())
listoflist = []
for i in range(0, n):
	x = input()
	y = list(x)
	listoflist.append(y)
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if listoflist[i][j] > listoflist[i + 1][j] and listoflist[i][j] > listoflist[i][j - 1] and (listoflist[i][j] > listoflist[i - 1][j]) and (listoflist[i][j] > listoflist[i][j + 1]):
			listoflist[i][j] = 'X'
for element in listoflist:
	for item in element:
		print(item, end='')
	print(end='\n')


square_size = int(input())
map = []
hole_coords = []
for i in range(square_size):
	map.append(list(input()))
for i in range(1, square_size - 1):
	for j in range(1, square_size - 1):
		if int(map[i][j - 1]) < int(map[i][j]) and int(map[i][j + 1]) < int(map[i][j]) and (int(map[i - 1][j]) < int(map[i][j])) and (int(map[i + 1][j]) < int(map[i][j])):
			hole_coords.append((i, j))
for i in range(len(hole_coords)):
	map[hole_coords[i][0]][hole_coords[i][1]] = 'X'
for i in range(square_size):
	print(str.join('', map[i]))


N = int(input())
cavity_map = list()
for line in range(N):
	aLine = [int(char) for char in input()]
	cavity_map.extend(aLine)
for i in range(N * N):
	if i % N != 0 and (i + 1) % N != 0 and (i > N - 1) and (i < N * (N - 1)):
		currentValue = cavity_map[i]
		if cavity_map[i - 1] < currentValue and cavity_map[i - N] < currentValue and (cavity_map[i + 1] < currentValue) and (cavity_map[i + N] < currentValue):
			print('X', end='')
		else:
			print(currentValue, end='')
	else:
		print(cavity_map[i], end='')
	if (i + 1) % N == 0:
		print()


def is_edge(i, j):
	return i == 0 or j == 0 or i == T - 1 or (j == T - 1)
T = int(input())
Map = []
for _ in range(T):
	Map.append(list(map(int, list(input()))))
cavity = []
for i in range(T):
	for j in range(T):
		if not is_edge(i, j):
			val = Map[i][j]
			(top, bottom, left, right) = (Map[i - 1][j], Map[i + 1][j], Map[i][j - 1], Map[i][j + 1])
			if val > max(top, bottom, left, right):
				cavity.append((i, j))
for i in cavity:
	Map[i[0]][i[1]] = 'X'
for row in Map:
	print(''.join(map(str, row)))


n = int(input())
cavities = [[]] * n
for i in range(n):
	cavities[i] = [int(x) for x in input()]
print(''.join([str(x) for x in cavities[0]]))
for i in range(1, n - 1):
	for j in range(1, n - 1):
		try:
			if cavities[i][j] > cavities[i][j + 1] and cavities[i][j] > cavities[i][j - 1] and (cavities[i][j] > cavities[i - 1][j]) and (cavities[i][j] > cavities[i + 1][j]):
				cavities[i][j] = 'X'
		except TypeError:
			pass
	print(''.join([str(x) for x in cavities[i]]))
if n > 1:
	print(''.join([str(x) for x in cavities[n - 1]]))


def is_cavity(i, j, cavityMap):
	newList = [cavityMap[i - 1][j], cavityMap[i][j - 1], cavityMap[i][j + 1], cavityMap[i + 1][j]]
	for x in newList:
		if x == 'X' or int(x) >= int(cavityMap[i][j]):
			return False
	return True

def main():
	mapSize = int(input())
	cavityMap = []
	for i in range(mapSize):
		cavityMap.append(list(input()))
	for i in range(1, len(cavityMap) - 1):
		for j in range(1, len(cavityMap[i]) - 1):
			if is_cavity(i, j, cavityMap):
				cavityMap[i][j] = 'X'
	for i in cavityMap:
		retString = ''
		for j in i:
			retString += j
		print(retString)
main()


def main():
	length = int(input())
	board = []
	result = []
	for i in range(length):
		board.append(input())
	result.append(board[0])
	for i in range(1, len(board) - 1):
		result.append(board[i][0])
		for a in range(1, len(board[i]) - 1):
			mid = int(board[i][a])
			top = int(board[i - 1][a])
			right = int(board[i][a + 1])
			bottom = int(board[i + 1][a])
			left = int(board[i][a - 1])
			if mid > top and mid > right and (mid > bottom) and (mid > left):
				result[i] += 'X'
			else:
				result[i] += board[i][a]
		result[i] += board[i][-1]
	if length != 1:
		result.append(board[-1])
	for i in range(len(result)):
		print(result[i])
main()


import copy
s = int(input())
m = [[l for l in input()] for _ in range(s)]
r = copy.deepcopy(m)
for i in range(1, s - 1):
	for j in range(1, s - 1):
		if all([int(m[i][j]) > int(m[k][l]) for (k, l) in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]]):
			r[i][j] = 'X'
for i in range(s):
	print(''.join(r[i]))


n = int(input())
m = [list(input()) for _ in range(n)]
nm = [r[:] for r in m]
for r in range(1, n - 1):
	for c in range(1, n - 1):
		if max(m[r - 1][c], m[r + 1][c], m[r][c - 1], m[r][c + 1]) < m[r][c]:
			nm[r][c] = 'X'
print('\n'.join((''.join(l) for l in nm)))


n = int(input())
ar = [list(map(int, input().strip())) for i in range(n)]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if all((ar[i + y][j + x] != 'X' and ar[i + y][j + x] < ar[i][j] for (x, y) in [(1, 0), (-1, 0), (0, 1), (0, -1)])):
			ar[i][j] = 'X'
print('\n'.join((''.join(map(str, line)) for line in ar)))


from sys import stdin
from copy import deepcopy

def main():
	n = int(stdin.readline())
	M = []
	for i in range(n):
		row = [int(i) for i in stdin.readline().strip()]
		M.append(row)
	return compute_cavities(M, n)

def compute_cavities(M, N):
	Mcopy = deepcopy(M)
	rangeN = list(range(N))
	for i in rangeN[1:-1]:
		for j in rangeN[1:-1]:
			if is_cavity(M, i, j):
				Mcopy[i][j] = 'X'
	for row in Mcopy:
		print(*row, sep='')

def is_cavity(M, i, j):
	if M[i - 1][j] < M[i][j] and M[i + 1][j] < M[i][j] and (M[i][j - 1] < M[i][j]) and (M[i][j + 1] < M[i][j]):
		return True
	else:
		return False
main()


def _is_greater_than_neighbors(arr, i, j):
	if arr[i][j] <= arr[i - 1][j] or arr[i][j] <= arr[i + 1][j] or arr[i][j] <= arr[i][j - 1] or (arr[i][j] <= arr[i][j + 1]):
		return False
	return True

def find_cavities(arr):
	for i in range(1, len(arr) - 1):
		for j in range(1, len(arr) - 1):
			if _is_greater_than_neighbors(arr, i, j):
				arr[i][j] = 'X'
	return arr
n = int(input())
mp = []
for _ in range(n):
	mp.append(list(map(str, [int(el) for el in input().strip()])))
print('\n'.join((''.join(map(str, row)) for row in find_cavities(mp))))


n = int(input())
m = [0] * n
ans = [0] * n
for i in range(n):
	line = input()
	m[i] = [int(i) for i in line]
	ans[i] = [int(i) for i in line]
if n > 2:
	for row in range(1, n - 1):
		for col in range(1, n - 1):
			l = []
			cur = m[row][col]
			top = m[row - 1][col]
			bottom = m[row + 1][col]
			left = m[row][col - 1]
			right = m[row][col + 1]
			if top < cur and bottom < cur and (left < cur) and (right < cur):
				ans[row][col] = 'X'
for i in ans:
	print(''.join(map(str, i)))


mapSize = int(input())
allSpots = []
finishedA = []
for _ in range(mapSize):
	allSpots += [[0] * mapSize]
for _ in range(mapSize):
	finishedA += [[0] * mapSize]
for i in range(mapSize):
	row = input()
	for j in range(mapSize):
		allSpots[i][j] = row[j]
		finishedA[i][j] = row[j]
for i in range(1, mapSize - 1):
	for j in range(1, mapSize - 1):
		t = allSpots[i][j]
		if t > allSpots[i - 1][j]:
			if t > allSpots[i + 1][j]:
				if t > allSpots[i][j - 1]:
					if t > allSpots[i][j + 1]:
						finishedA[i][j] = 'X'
for i in range(mapSize):
	s = ''
	for j in range(mapSize):
		s += finishedA[i][j]
	print(s)


n = int(input())
a = [list(input()) for _ in range(n)]

def getval(p, off):
	px = p[0] + off[0]
	py = p[1] + off[1]
	pi = a[px][py]
	return 10 if pi == 'X' else int(pi)
for i in range(1, n - 1):
	for j in range(1, n - 1):
		p = (i, j)
		if getval(p, (0, 0)) > max((getval(p, off) for off in ((0, 1), (0, -1), (-1, 0), (1, 0)))):
			a[i][j] = 'X'
for row in a:
	print(''.join(row))


def isCavity(A, i, j):
	a = A[i][j]
	return A[i - 1][j] < a and A[i + 1][j] < a and (A[i][j - 1] < a) and (A[i][j + 1] < a)
n = int(input())
A = [[int(s) for s in list(input().strip())] for i in range(n)]
B = [list(a) for a in A]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if isCavity(A, i, j):
			B[i][j] = 'X'
print('\n'.join([''.join(map(str, b)) for b in B]))


from itertools import product
n = int(input())
map = []
for i in range(n):
	map.append(input())

def check_cell(x, y, map):
	for i in ((-1, 0), (1, 0), (0, -1), (0, 1)):
		if not (i[0] == 0 and i[1] == 0) and int(map[x + i[0]][y + i[1]]) >= int(map[x][y]):
			return False
	else:
		return True
maplist = []
for x in map:
	l = list(x)
	maplist.append(l)
for i in range(1, len(map) - 1):
	change_list = []
	for j in range(1, len(map) - 1):
		if check_cell(i, j, map):
			maplist[i][j] = 'X'
for x in maplist:
	print(''.join(x))


n = int(input())
tab = []
for i in range(n):
	tab.append(list(map(int, list(input()))))
for i in range(n):
	for j in range(n):
		if i == 0 or i == n - 1 or j == 0 or (j == n - 1):
			print(tab[i][j], end='')
			continue
		if tab[i - 1][j] < tab[i][j] and tab[i + 1][j] < tab[i][j] and (tab[i][j - 1] < tab[i][j]) and (tab[i][j + 1] < tab[i][j]):
			print('X', end='')
		else:
			print(tab[i][j], end='')
	print('')


n = int(input())
map1 = []
map_copy = []
for counter in range(n):
	area = [int(number) for number in input()]
	map_copy.append(area.copy())
	map1.append(area)
for counter1 in range(1, len(map1) - 1):
	area = map_copy[counter1]
	counter2 = 1
	while counter2 < n - 1:
		try:
			if area[counter2 - 1] < area[counter2] and area[counter2] > area[counter2 + 1]:
				if map_copy[counter1 + 1][counter2] < area[counter2] > map_copy[counter1 - 1][counter2]:
					map1[counter1][counter2] = 'X'
			counter2 += 1
		except TypeError:
			print(area)
			raise
for area in map1:
	for square in area:
		print(square, end='')
	print()


import sys
DEV = False
Cavity = 'X'

def Ctx_ch(Row_idx_, Col_idx_, Rows_):
	for ctx_row_idx in range(Row_idx_ - 1, Row_idx_ + 2, 1):
		for ctx_col_idx in range(Col_idx_ - 1, Col_idx_ + 2, 1):
			if ctx_row_idx == Row_idx_ and ctx_col_idx == Col_idx_:
				continue
			yield Rows_[ctx_row_idx][ctx_col_idx]
if DEV:
	f = open('test_data.txt', 'r')
	map_size = int(f.readline().strip())
else:
	map_size = int(input().strip())
Rows_in = ['' for j in range(0, map_size, 1)]
Rows_out = ['' for j in range(0, map_size, 1)]
for idx in range(0, map_size, 1):
	if DEV:
		row = f.readline().strip()
	else:
		row = input().strip()
	Rows_in[idx] = row
Rows_out[0] = Rows_in[0]
Rows_out[map_size - 1] = Rows_in[map_size - 1]
for row_idx in range(1, map_size - 1, 1):
	row = Rows_in[row_idx][0]
	for col_idx in range(1, map_size - 1, 1):
		out_ch = Cavity
		in_ch = Rows_in[row_idx][col_idx]
		for ctx_row_idx in range(row_idx - 1, row_idx + 2, 1):
			for ctx_col_idx in range(col_idx - 1, col_idx + 2, 1):
				if ctx_row_idx == row_idx and ctx_col_idx == col_idx:
					continue
				if ctx_row_idx != row_idx and ctx_col_idx != col_idx:
					continue
				ctx_ch = Rows_in[ctx_row_idx][ctx_col_idx]
				if ctx_ch >= in_ch:
					out_ch = in_ch
					break
		row += out_ch
	row += Rows_in[row_idx][map_size - 1]
	Rows_out[row_idx] = row
if DEV:
	f.close()
for row in Rows_out:
	print(row)
sys.exit()


n = int(input())
m = []
for _ in range(n):
	m.append([int(x) for x in input()])
print(''.join(map(str, m[0])))
for i in range(1, n - 1):
	print(m[i][0], end='')
	for j in range(1, n - 1):
		if m[i][j] > m[i][j + 1] and m[i][j] > m[i][j - 1] and (m[i][j] > m[i - 1][j]) and (m[i][j] > m[i + 1][j]):
			print('X', end='')
		else:
			print(m[i][j], end='')
	print(m[i][n - 1])
if n > 1:
	print(''.join(map(str, m[n - 1])))


size = int(input())
depths = list()
for _ in range(0, size):
	row = [int(n) for n in input()]
	depths.append(row)
for i in range(1, len(depths) - 1):
	for j in range(1, len(depths) - 1):
		if depths[i][j] > depths[i][j + 1] and depths[i][j] > depths[i][j - 1] and (depths[i][j] > depths[i + 1][j]) and (depths[i][j] > depths[i - 1][j]):
			depths[i][j] = 10
for row in depths:
	out = ''
	for depth in row:
		if depth == 10:
			out += 'X'
		else:
			out += str(depth)
	print(out)


n = int(input())
l = []
for i in range(n):
	l.append(input())
xi = (0, 1, 0, -1)
yi = (1, 0, -1, 0)
print(l[0])
for i in range(1, n - 1):
	print(l[i][0], end='')
	for j in range(1, n - 1):
		check = True
		for k in range(4):
			xc = i + xi[k]
			yc = j + yi[k]
			if l[xc][yc] >= l[i][j]:
				check = False
		print((l[i][j], 'X')[check], end='')
	if n != 1:
		print(l[i][-1])
	else:
		print()
if n != 1:
	print(l[-1])


from functools import reduce

def is_cavity(A, i, j):
	return reduce(lambda acc, val: acc and A[i][j] > val, [A[x][y] for (x, y) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]], True)
N = int(input())
A = [list(map(int, input())) for L in range(N)]
B = [a.copy() for a in A]
for i in range(1, N - 1):
	for j in range(1, N - 1):
		if is_cavity(A, i, j):
			B[i][j] = 'X'
for b in B:
	print(''.join(map(str, b)))


def main():
	n = int(input())
	cmap = []
	for i in range(n):
		cmap.append(input())
	points = []
	for i in range(1, n - 1):
		for j in range(1, n - 1):
			cell = int(cmap[i][j])
			if cell > int(cmap[i][j - 1]) and cell > int(cmap[i][j + 1]) and (cell > int(cmap[i - 1][j])) and (cell > int(cmap[i + 1][j])):
				points.append([i, j])
	for point in points:
		string = ''
		cavity = True
		for i in range(len(cmap[point[0]])):
			if i == point[1] and cavity:
				string += 'X'
				cavity = False
			else:
				string += cmap[point[0]][i]
		cmap[point[0]] = string
	for i in range(n):
		for j in range(n):
			print(cmap[i][j], end='')
		print()
main()


N = int(input())
cmap = [[] * N] * N
for i in range(N):
	cmap[i] = [x for x in input()]
for i in range(1, N - 1):
	for j in range(1, N - 1):
		c = cmap[i][j]
		if c > cmap[i - 1][j] and c > cmap[i + 1][j] and (c > cmap[i][j - 1]) and (c > cmap[i][j + 1]):
			cmap[i][j] = 'X'
for i in cmap:
	for j in i:
		print(j, end='')
	print()


n = int(input())

def readRow(row):
	return list(map(int, row))
board = [readRow(input()) for _ in range(n)]
cavity = []
for r in range(1, n - 1):
	for c in range(1, n - 1):
		if board[r][c] > board[r - 1][c] and board[r][c] > board[r][c + 1] and (board[r][c] > board[r + 1][c]) and (board[r][c] > board[r][c - 1]):
			cavity.append((r, c))
for (x, y) in cavity:
	board[x][y] = 'X'
for row in board:
	print(''.join(map(str, row)))


def main():
	length = int(input())
	board = []
	result = []
	for i in range(length):
		board.append(input())
	result.append(board[0])
	for i in range(1, len(board) - 1):
		result.append(board[i][0])
		for a in range(1, len(board[i]) - 1):
			mid = int(board[i][a])
			top = int(board[i - 1][a])
			right = int(board[i][a + 1])
			bottom = int(board[i + 1][a])
			left = int(board[i][a - 1])
			if mid > top and mid > right and (mid > bottom) and (mid > left):
				result[i] += 'X'
			else:
				result[i] += board[i][a]
		result[i] += board[i][-1]
	if length != 1:
		result.append(board[-1])
	for i in range(len(result)):
		print(result[i])
main()


l = []
for j in range(int(input())):
	inp = list(input())
	l.append(inp)
for i in range(1, len(inp) - 1):
	for j in range(1, len(inp) - 1):
		if l[i][j - 1] < l[i][j] > l[i][j + 1] and l[i - 1][j] < l[i][j] > l[i + 1][j]:
			l[i][j] = 'X'
for m in l:
	print(''.join(m))


row = int(input())
dep = []
for i in range(row):
	dep.append(input())
for i in range(1, row - 1):
	for j in range(1, row - 1):
		if str(dep[i][j]).isalnum() and dep[i][j] > dep[i - 1][j] and (dep[i][j] > dep[i + 1][j]) and (dep[i][j] > dep[i][j - 1]) and (dep[i][j] > dep[i][j + 1]):
			x = dep[i]
			x = x[:j] + 'X' + x[j + 1:]
			dep[i] = x
for i in range(row):
	print(dep[i])


n = int(input())
map = []
for row in range(n):
	map.append([int(x) for x in input()])
for row in range(1, n - 1):
	for column in range(1, n - 1):
		currentValue = map[row][column]
		neighbourValues = [map[row - 1][column], map[row + 1][column], map[row][column + 1], map[row][column - 1]]
		isCavity = True
		for neighbour in neighbourValues:
			if neighbour is 'X' or currentValue <= neighbour:
				isCavity = False
				break
		if isCavity:
			map[row][column] = 'X'
for row in range(n):
	for element in map[row]:
		print(element, end='')
	print('')


from copy import deepcopy
size = int(input())
matrix = []
for row in range(size):
	matrix.append([int(x) for x in list(input())])
cp = deepcopy(matrix)
for i in range(size):
	for j in range(size):
		if i - 1 < 0 or i + 1 >= size or j - 1 < 0 or (j + 1 >= size):
			continue
		candidate = matrix[i][j]
		if matrix[i - 1][j] < candidate and matrix[i][j - 1] < candidate and (matrix[i][j + 1] < candidate) and (matrix[i + 1][j] < candidate):
			cp[i][j] = 'X'
for row in cp:
	print(''.join(map(lambda x: str(x), row)))


n = int(input())
a = []
for _ in range(n):
	a.append([int(x) for x in list(input())])
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if abs(a[i][j]) > abs(a[i - 1][j]) and abs(a[i][j]) > abs(a[i + 1][j]) and (abs(a[i][j]) > abs(a[i][j - 1])) and (abs(a[i][j]) > abs(a[i][j + 1])):
			a[i][j] = -a[i][j]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if a[i][j] < 0:
			a[i][j] = 'X'
for i in range(n):
	print(''.join(map(str, a[i])))


from sys import stdin
n = int(stdin.readline())
grid = []
for i in range(n):
	grid.append(list(stdin.readline().strip()))

def is_cavity(grid, i, j):
	n = len(grid)
	depth = grid[i][j]
	if depth <= grid[i - 1][j]:
		return False
	if depth <= grid[i + 1][j]:
		return False
	if depth <= grid[i][j - 1]:
		return False
	if depth <= grid[i][j + 1]:
		return False
	return True
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if is_cavity(grid, i, j):
			grid[i][j] = 'X'
for i in range(n):
	print(''.join(grid[i]))


N = int(input())
arString = [list(input()) for i in range(0, N)]
arInt = [[ord(C) - ord('0') for C in S] for S in arString]
if N > 2:
	for i in range(1, N - 1):
		for j in range(1, N - 1):
			x = arInt[i][j]
			if x > arInt[i + 1][j] and x > arInt[i - 1][j] and (x > arInt[i][j + 1]) and (x > arInt[i][j - 1]):
				arString[i][j] = 'X'
for i in range(0, N):
	print(''.join(arString[i]))


n = int(input())
array = []
for line in range(n):
	array.append(list(map(int, input())))
Xs = []
for i in range(1, n - 1):
	for j in range(1, n - 1):
		test = array[i][j]
		sides = [array[i][j - 1], array[i][j + 1], array[i - 1][j], array[i + 1][j]]
		if all((x < test for x in sides)):
			Xs.append((i, j))
for x in Xs:
	array[x[0]][x[1]] = 'X'
for line in array:
	print(''.join(map(str, line)))


import sys
size = int(sys.stdin.readline())
grid = []
for i in range(size):
	row = sys.stdin.readline().strip()
	grid.append(row)
for row in range(1, size - 1):
	for col in range(1, size - 1):
		left = grid[row][col] > grid[row][col - 1]
		right = grid[row][col] > grid[row][col + 1]
		up = grid[row][col] > grid[row + 1][col]
		down = grid[row][col] > grid[row - 1][col]
		if left == False or right == False or up == False or (down == False):
			pass
		else:
			grid[row] = grid[row][:col] + 'X' + grid[row][col + 1:]
print('\n'.join(grid))


def find_cavities(arr):
	cavities = []
	row = 1
	while row < len(arr) - 1:
		col = 1
		while col < len(arr) - 1:
			curr = arr[row][col]
			checks = [arr[row + 1][col] < curr, arr[row - 1][col] < curr, arr[row][col + 1] < curr, arr[row][col - 1] < curr]
			if all(checks):
				cavities.append((row, col))
			col += 1
		row += 1
	for (row, col) in cavities:
		arr[row][col] = 'X'

def print_arr(arr):
	for i in arr:
		print(''.join([str(x) for x in i]))
size = int(input())
arr = list()
while size > 0:
	arr.append([int(x) for x in input()])
	size -= 1
find_cavities(arr)
print_arr(arr)


N = int(input())
inp = [[int(i) for i in list(input())] for _ in range(N)]
res = []
for x in range(1, N - 1):
	for y in range(1, N - 1):
		if inp[x][y] > inp[x - 1][y] and inp[x][y] > inp[x][y - 1] and (inp[x][y] > inp[x + 1][y]) and (inp[x][y] > inp[x][y + 1]):
			res.append([x, y])
for (x, y) in res:
	inp[x][y] = 'X'
for r in inp:
	print(*r, sep='')


n = int(input())
a = [[0 for j in range(n)] for i in range(n)]
for i in range(0, n):
	s = input()
	for j in range(0, n):
		a[i][j] = s[j:j + 1]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if a[i][j] > a[i][j + 1] and a[i][j] > a[i][j - 1] and (a[i][j] > a[i - 1][j]) and (a[i][j] > a[i + 1][j]):
			a[i][j] = 'X'
for i in range(0, n):
	s = ''
	for j in range(0, n):
		s += a[i][j]
	print(s)


from copy import deepcopy

def build_cavity_string(grid, n):
	grid2 = deepcopy(grid)
	for i in range(1, n - 1):
		for j in range(1, n - 1):
			v = grid[i][j]
			up = grid[i][j + 1]
			down = grid[i][j - 1]
			left = grid[i - 1][j]
			right = grid[i + 1][j]
			if v > up and v > down and (v > left) and (v > right):
				grid2[i][j] = 'X'
	string = ''
	for i in range(0, n):
		for j in range(0, n):
			string += str(grid2[i][j])
		print(string)
		string = ''
n = int(input())
grid = []
for i in range(0, n):
	grid.append([int(i) for i in input()])
build_cavity_string(grid, n)


n = int(input())
M = [list(input()) for i in range(n)]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		try:
			a = int(M[i][j])
			z = [int(M[i + 1][j]), int(M[i - 1][j]), int(M[i][j + 1]), int(M[i][j - 1]), int(M[i][j])]
			if max(z) == a and z.count(a) == 1:
				M[i][j] = 'X'
		except:
			pass
for i in M:
	print(''.join(i))


def markCavities(grid):
	markedGrid = [list(row) for row in grid]
	for r in range(1, len(grid) - 1):
		for c in range(1, len(grid[r]) - 1):
			neighbors = (grid[r - 1][c], grid[r + 1][c], grid[r][c - 1], grid[r][c + 1])
			for neighbor in neighbors:
				if neighbor >= grid[r][c]:
					break
			else:
				markedGrid[r][c] = 'X'
	return markedGrid
n = int(input())
grid = tuple((tuple((int(i) for i in input())) for j in range(n)))
result = markCavities(grid)
for row in result:
	print(''.join((str(i) for i in row)))


n = int(input())
m = [0] * n
ans = [0] * n
for i in range(n):
	line = input()
	m[i] = [int(i) for i in line]
	ans[i] = [int(i) for i in line]
if n > 2:
	for row in range(1, n - 1):
		for col in range(1, n - 1):
			l = []
			cur = m[row][col]
			top = m[row - 1][col]
			bottom = m[row + 1][col]
			left = m[row][col - 1]
			right = m[row][col + 1]
			if top < cur and bottom < cur and (left < cur) and (right < cur):
				ans[row][col] = 'X'
for i in ans:
	print(''.join(map(str, i)))


__author__ = 'danielbaeck'
n = int(input())
m = []
ma = []
p = [(-1, 0), (1, 0), (0, 1), (0, -1)]
for i in range(n):
	l = [int(r) for r in input()]
	m.append(l)
	ma.append(l[:])
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if max([m[i + k[0]][j + k[1]] for k in p]) < m[i][j]:
			ma[i][j] = 'X'
for i in ma:
	print(''.join([str(j) for j in i]))


n = int(input())
m = [[int(x) for x in list(input())] for _ in range(n)]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		neighbors = set([m[i - 1][j], m[i + 1][j], m[i][j - 1], m[i][j + 1]])
		if 'X' not in neighbors and m[i][j] > max(neighbors):
			m[i][j] = 'X'
[print(''.join([str(y) for y in x])) for x in m]


def putCrosses(board):
	list = []
	for i in range(1, len(board) - 1):
		for j in range(1, len(board) - 1):
			value = board[i][j]
			if board[i][j - 1] < value and board[i][j + 1] < value and (board[i + 1][j] < value) and (board[i - 1][j] < value):
				list.append((i, j))
	for (a, b) in list:
		board[a][b] = 'X'
	return board

def printSquare(sA):
	for array in sA:
		printArray(array)

def printArray(array):
	output = ''
	for a in array:
		output += str(a)
	print(output)
sizeOfInput = int(input())
board = []
for i in range(sizeOfInput):
	row = input()
	board.append([])
	for r in row:
		board[i].append(int(r))
crossed = putCrosses(board)
printSquare(crossed)


n = int(input())
cav_map = []
for i in range(n):
	cav_map.append(list(input()))
	locations = []
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if cav_map[i][j] > cav_map[i - 1][j] and cav_map[i][j] > cav_map[i + 1][j]:
			if cav_map[i][j] > cav_map[i][j + 1] and cav_map[i][j] > cav_map[i][j - 1]:
				locations.append([i, j])
for location in locations:
	cav_map[location[0]][location[1]] = 'X'
for i in cav_map:
	print(''.join(i))


import sys
T = int(input())
count = 0
cavity = []
LIST = []
while count < T:
	temp = input()
	LIST.append(temp)
	count = count + 1
count = 0
count1 = 1
if T == 1:
	print(LIST[0])
	sys.exit()
print(LIST[0])
while count1 < T - 1:
	del cavity[:]
	lists_prev = list(LIST[count1 - 1])
	lists = list(LIST[count1])
	lists_next = list(LIST[count1 + 1])
	for i in range(1, len(lists) - 1):
		if int(lists[i]) > int(lists[i - 1]) and int(lists[i]) > int(lists[i + 1]) and (int(lists[i]) > int(lists_prev[i])) and (int(lists[i]) > int(lists_next[i])):
			cavity.append(i)
		else:
			pass
	for i in cavity:
		lists[int(i)] = 'X'
	print(''.join(lists))
	count = count + 1
	count1 = count1 + 1
print(LIST[-1])


def get_input():
	map_list = []
	size_of_map = int(input())
	for _ in range(size_of_map):
		map_list.append(list(input()))
	return map_list

def main():
	map_list = get_input()
	for j in range(1, len(map_list) - 1):
		for k in range(1, len(map_list) - 1):
			if map_list[j - 1][k] < map_list[j][k] and map_list[j][k - 1] < map_list[j][k] and (map_list[j][k + 1] < map_list[j][k]) and (map_list[j + 1][k] < map_list[j][k]):
				map_list[j][k] = 'X'
	for line in map_list:
		print(''.join(line))
main()


import copy
nMap = int(input())
myMap = []
for i in range(0, nMap):
	myMap.append(list(map(int, list(input()))))
newMap = copy.deepcopy(myMap)
for i in range(1, nMap - 1):
	for j in range(1, nMap - 1):
		if myMap[i][j] > myMap[i - 1][j] and myMap[i][j] > myMap[i + 1][j] and (myMap[i][j] > myMap[i][j - 1]) and (myMap[i][j] > myMap[i][j + 1]):
			newMap[i][j] = 'X'
for i in newMap:
	for j in i:
		print(j, end='')
	print()


n = int(input())
matrix = []
for i in [1] * n:
	matrix.append(list(map(int, input())))
st = set()
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if matrix[i + 1][j] < matrix[i][j] > matrix[i - 1][j] and matrix[i][j + 1] < matrix[i][j] > matrix[i][j - 1]:
			st.add((i, j))
for pair in st:
	(i, j) = pair
	matrix[i][j] = 'X'
for a in matrix:
	print(*a, sep='')


data = []
n = int(input())
for i in range(n):
	data.append(list(map(int, input())))
for i in range(n):
	s = ''
	for j in range(n):
		if i == 0 or j == 0 or i == n - 1 or (j == n - 1):
			s += str(data[i][j])
		else:
			x = data[i][j]
			if data[i - 1][j] < x and data[i][j - 1] < x and (data[i][j + 1] < x) and (data[i + 1][j] < x):
				s += 'X'
			else:
				s += str(data[i][j])
	print(s)


N = int(input())
m = []
for i in range(N):
	m.append(list(map(int, input())))
indexes = []
for i in range(1, N - 1):
	for j in range(1, N - 1):
		c = m[i][j]
		if c > m[i - 1][j] and c > m[i + 1][j] and (c > m[i][j - 1]) and (c > m[i][j + 1]):
			indexes.append((i, j))
for pair in indexes:
	m[pair[0]][pair[1]] = 'X'
for row in m:
	print(''.join(map(str, row)))


import sys

def main():
	n = int(input())
	original_map = [[int(x) for x in list(str(input()))] for i in range(n)]
	cavity_map = [[y for y in x] for x in original_map]
	if n == 1 or n == 2:
		output(original_map)
	for x in range(1, n - 1):
		for y in range(1, n - 1):
			if is_cavity(original_map, x, y):
				cavity_map[x][y] = 'X'
	output(cavity_map)

def is_cavity(original_map, x, y):
	if original_map[x + 1][y] >= original_map[x][y]:
		return False
	if original_map[x - 1][y] >= original_map[x][y]:
		return False
	if original_map[x][y + 1] >= original_map[x][y]:
		return False
	if original_map[x][y - 1] >= original_map[x][y]:
		return False
	return True

def output(map):
	print('\n'.join([''.join([str(y) for y in x]) for x in map]))
	sys.exit()
main()


n = int(input().strip())
lines = []
for _ in range(n):
	lines.append([c for c in input().strip()])
for i in range(1, len(lines) - 1):
	for j in range(1, len(lines[i]) - 1):
		if lines[i - 1][j] < lines[i][j] > lines[i + 1][j] and lines[i][j - 1] < lines[i][j] > lines[i][j + 1]:
			lines[i][j] = 'X'
for line in lines:
	print(''.join(map(str, line)))


def run():
	n = int(input())
	ar = [[]] * n
	for i in range(n):
		ar[i] = [''] * n
		line = input()
		for i2 in range(n):
			ar[i][i2] = line[i2]
	for k in range(1, n - 1):
		for k2 in range(1, n - 1):
			here = ar[k][k2]
			if here > ar[k + 1][k2] and here > ar[k - 1][k2] and (here > ar[k][k2 + 1]) and (here > ar[k][k2 - 1]):
				ar[k][k2] = 'X'
	for row in ar:
		for col in row:
			print(col, end='')
		print()
run()


import sys
n = int(sys.stdin.readline())
cmap = []
for line in sys.stdin.readlines():
	x = []
	for d in line.strip():
		x.append(int(d))
	cmap.append(x)
cavities = []
for i in range(0, n):
	s = ''
	for j in range(0, n):
		c = cmap[i][j]
		if i > 0 and i < n - 1 and (j > 0) and (j < n - 1) and (cmap[i - 1][j] < c) and (cmap[i + 1][j] < c) and (cmap[i][j - 1] < c) and (cmap[i][j + 1] < c):
			s += 'X'
		else:
			s += str(cmap[i][j])
	cavities.append(s)
for s in cavities:
	print(s)


__author__ = 'nolan'

def parseInput():
	n = int(input())
	arr = []
	for i in range(0, n):
		line = input()
		tmp = list(map(int, line))
		arr.append(tmp)
	return (n, arr)

def checkUpper(arr, posY, posX, val):
	if arr[posY - 1][posX] != 'X' and arr[posY - 1][posX] < val:
		return True
	return False

def checkLeft(arr, posY, posX, val):
	if arr[posY][posX - 1] != 'X' and arr[posY][posX - 1] < val:
		return True
	return False

def checkRight(arr, posY, posX, val):
	if arr[posY][posX + 1] != 'X' and arr[posY][posX + 1] < val:
		return True
	return False

def checkBottom(arr, posY, posX, val):
	if arr[posY + 1][posX] != 'X' and arr[posY + 1][posX] < val:
		return True
	return False

def checkAll(arr, y, x, val):
	if checkUpper(arr, y, x, val) and checkLeft(arr, y, x, val) and checkRight(arr, y, x, val) and checkBottom(arr, y, x, val):
		return True
	return False

def findCavity(n, arr):
	y = 0
	x = 0
	while y < n:
		x = 0
		while x < n:
			if (y != 0 and y != n - 1) and (x != 0 and x != n - 1):
				if checkAll(arr, y, x, arr[y][x]):
					arr[y][x] = 'X'
			x += 1
		y += 1
	return arr

def displayOutput(arr):
	y = 0
	x = 0
	while y < n:
		x = 0
		while x < n:
			print(arr[y][x], end='')
			x += 1
		print(end='\n')
		y += 1
(n, arr) = parseInput()
arr = findCavity(n, arr)
displayOutput(arr)


area = []
for row_index in range(int(input())):
	area.append([int(x) for x in input()])
cavities = []
for (y, row) in enumerate(area[1:-1]):
	y += 1
	for (x, value) in enumerate(row[1:-1]):
		x += 1
		top = area[y - 1][x]
		bottom = area[y + 1][x]
		left = area[y][x - 1]
		right = area[y][x + 1]
		if all((value > top, value > bottom, value > left, value > right)):
			cavities.append((y, x))
for (y, x) in cavities:
	area[y][x] = 'X'
for row in area:
	print(''.join(map(str, row)))


N = int(input())
D = [[int(d) for d in input()] for _ in range(N)]
R = [[d for d in D[i]] for i in range(N)]
for i in range(1, N - 1):
	for j in range(1, N - 1):
		if D[i][j] > D[i][j + 1] and D[i][j] > D[i][j - 1] and (D[i][j] > D[i + 1][j]) and (D[i][j] > D[i - 1][j]):
			R[i][j] = 'X'
for i in range(N):
	print(''.join((str(d) for d in R[i])))


import sys

def check_adjs(matrix, i, j):
	to_check = matrix[i][j]
	return to_check > matrix[i - 1][j] and to_check > matrix[i][j - 1] and (to_check > matrix[i + 1][j]) and (to_check > matrix[i][j + 1])
n = int(sys.stdin.readline().strip())
matrix = list()
for i in range(n):
	line_str = sys.stdin.readline().strip()
	line_int = list()
	for char in line_str:
		line_int.append(int(char))
	matrix.append(line_int)
out_matrix = [[el for el in line] for line in matrix]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if check_adjs(matrix, i, j):
			out_matrix[i][j] = 'X'
for line in out_matrix:
	for el in line:
		print(el, end='')
	print()


N = int(input())
M = []
for i in range(N):
	M.append(list(input()))
P = [[True] * N for i in range(N)]
for i in range(N):
	for j in range(N):
		if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
			P[i][j] = False
			continue
		if P[i][j]:
			if M[i][j] <= M[i - 1][j]:
				P[i][j] = False
				continue
			if M[i][j] <= M[i][j - 1]:
				P[i][j] = False
				continue
			if M[i][j] <= M[i + 1][j]:
				P[i][j] = False
				continue
			else:
				P[i + 1][j] = False
			if M[i][j] <= M[i][j + 1]:
				P[i][j] = False
				continue
			else:
				P[i][j + 1] = False
for i in range(N):
	for j in range(N):
		if P[i][j]:
			M[i][j] = 'X'
print('\n'.join((''.join((x for x in A)) for A in M)))


n = int(input())
Matrix = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
	input1 = input()
	tmp = [int(x) for x in input1]
	for j in range(n):
		Matrix[i][j] = tmp[j]

def getMaxAdjacent(a, i, j):
	upper = a[i - 1][j]
	lower = a[i + 1][j]
	left = a[i][j - 1]
	right = a[i][j + 1]
	if not (upper == 'X' or left == 'X'):
		return max(upper, lower, left, right)
	else:
		return 'adj_cavity'
for i in range(1, n - 1):
	for j in range(1, n - 1):
		max_adj = getMaxAdjacent(Matrix, i, j)
		if not max_adj == 'adj_cavity':
			if Matrix[i][j] > max_adj:
				Matrix[i][j] = 'X'
for i in range(n):
	print(''.join([str(x) for x in Matrix[i][:]]))


n = int(input())
m = [[int(x) for x in list(input())] for _ in range(n)]
ans = [['' for _ in range(n)] for _ in range(n)]
adj = [(-1, 0), (1, 0), (0, 1), (0, -1)]
ans[0] = [str(x) for x in m[0]]
ans[-1] = [str(x) for x in m[-1]]
for i in range(1, n - 1):
	ans[i][0] = str(m[i][0])
	ans[i][-1] = str(m[i][-1])
for i in range(1, n - 1):
	for j in range(1, n - 1):
		deepest = max((m[i + a][j + b] for (a, b) in adj))
		if m[i][j] > deepest:
			ans[i][j] = 'X'
		else:
			ans[i][j] = str(m[i][j])
for r in ans:
	print(''.join(r))


n = int(input())
m = []
for x in range(n):
	m.append(list(map(int, input())))
for x in range(1, n - 1):
	for y in range(1, n - 1):
		if m[x][y] > m[x + 1][y] and m[x][y] > m[x - 1][y] and (m[x][y] > m[x][y + 1]) and (m[x][y] > m[x][y - 1]):
			m[x][y] = 10
for x in range(0, n):
	for y in range(0, n):
		m[x][y] = 'X' if m[x][y] == 10 else m[x][y]
		print(m[x][y], end='')
	print()


def compare_adjacent(m, i, j):
	if m[i - 1][j] < m[i][j] and m[i + 1][j] < m[i][j] and (m[i][j - 1] < m[i][j]) and (m[i][j + 1] < m[i][j]):
		return True
	else:
		return False
n = int(input())
m = []
for i in range(n):
	row = [int(c) for c in input()]
	m.append(row)
cavity_map = [row[:] for row in m]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if compare_adjacent(m, i, j):
			cavity_map[i][j] = 'X'
print('\n'.join([''.join(map(str, row)) for row in cavity_map]))


n = int(input())
m = []
for i in range(n):
	m.append([int(c) for c in input()])
for i in range(n):
	if i == 0 or i == n - 1:
		print(''.join(map(str, m[i])))
	else:
		print(m[i][0], end='')
		for j in range(1, n - 1):
			if m[i][j] > m[i][j - 1] and m[i][j] > m[i][j + 1] and (m[i][j] > m[i + 1][j]) and (m[i][j] > m[i - 1][j]):
				print('X', end='')
			else:
				print(m[i][j], end='')
		print(m[i][-1])


n = int(input())
tabl = []
for i in range(n):
	tabl.append([int(x) for x in list(input())])
out = ''
for i in range(n):
	for j in range(n):
		if i != 0 and j != 0 and (i != n - 1) and (j != n - 1) and (tabl[i - 1][j] < tabl[i][j]) and (tabl[i + 1][j] < tabl[i][j]) and (tabl[i][j - 1] < tabl[i][j]) and (tabl[i][j + 1] < tabl[i][j]):
			out += 'X'
		else:
			out += str(tabl[i][j])
	out += '\n'
print(out[:-1])


n = int(input())
mat = []
for _ in range(n):
	r = list(map(int, list(input().strip())))
	mat.append(r)
for i in range(1, n - 1):
	for j in range(1, n - 1):
		cur = mat[i][j]
		try:
			potential_cavity = cur > mat[i - 1][j] and cur > mat[i + 1][j] and (cur > mat[i][j - 1]) and (cur > mat[i][j + 1])
		except TypeError:
			continue
		if potential_cavity:
			mat[i][j] = 'X'
for row in mat:
	print(''.join(map(str, row)))


def cavities(grid):
	cavitymap = []
	for i in range(len(grid)):
		row = ''
		for j in range(len(grid)):
			if i == 0 or i == len(grid) - 1 or j == 0 or (j == len(grid) - 1):
				row += str(grid[i][j])
			elif grid[i][j] > grid[i - 1][j] and grid[i][j] > grid[i + 1][j] and (grid[i][j] > grid[i][j - 1]) and (grid[i][j] > grid[i][j + 1]):
				row += 'X'
			else:
				row += str(grid[i][j])
		cavitymap.append(row)
	return cavitymap
n = int(input())
grid = []
for i in range(n):
	grid.append([int(x) for x in input()])
res = cavities(grid)
print('\n'.join(res))


n = int(input())
a = []
for i in range(n):
	a.append(input())
s = a[0]
s += '\n'
for i in range(1, n - 1):
	s += a[i][0]
	for j in range(1, n - 1):
		c = a[i][j]
		if a[i - 1][j] < c and a[i + 1][j] < c and (a[i][j + 1] < c) and (a[i][j - 1] < c):
			s += 'X'
		else:
			s += c
	s += a[i][-1]
	s += '\n'
if n > 1:
	s += a[-1] + '\n'
print(s)


N = int(input())
sq = [list(map(int, input())) for i in range(N)]
oSq = [sqY[:] for sqY in sq]
for y in range(N):
	if 0 < y < N - 1:
		for x in range(1, N - 1):
			v = sq[y][x]
			w = max(v - 1, sq[y - 1][x], sq[y][x - 1], sq[y][x + 1], sq[y + 1][x])
			if v > w:
				oSq[y][x] = 'X'
	print(''.join(map(str, oSq[y])))


import sys

def main():
	n = int(input())
	m = []
	for i in range(n):
		m.append([x for x in list(input())])
	for i in range(1, n - 1):
		for j in range(1, n - 1):
			if m[i][j] > m[i - 1][j] and m[i][j] > m[i][j - 1] and (m[i][j] > m[i + 1][j]) and (m[i][j] > m[i][j + 1]):
				m[i][j] = 'X'
	for i in range(n):
		for j in range(n):
			sys.stdout.write(m[i][j])
		print()
main()


n = int(input())
grid = []
for _ in range(n):
	grid.append([ord(x) for x in input()])
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if max(grid[i][j], grid[i - 1][j] + 1, grid[i + 1][j] + 1, grid[i][j - 1] + 1, grid[i][j + 1] + 1) == grid[i][j]:
			grid[i][j] = ord('X')
for row in grid:
	print(''.join([chr(x) for x in row]))


def checkCavity(n, l):
	for x in range(1, n + 1):
		for y in range(n):
			if x == 1 or x == n or y == 0 or (y == n - 1):
				print(l[x][y], end='')
				continue
			if l[x][y] > l[x][y - 1] and l[x][y - 1] != 'X':
				if l[x][y] > l[x - 1][y] and l[x - 1][y] != 'X':
					if l[x][y] > l[x][y + 1]:
						if l[x][y] > l[x + 1][y]:
							l[x][y] = 'X'
							print(l[x][y], end='')
							continue
			print(l[x][y], end='')
		print()
n = int(input())
l = [[[] for i in range(n)]]
for _ in range(n):
	ls = list(input())
	l.append(ls)
checkCavity(n, l)


import sys
n = int(input())
m = []
s = 0
for _ in range(n):
	s = input().strip()
	for k in s:
		m.append(int(k))
if n == 1:
	print(s)
	sys.exit()
print(''.join(map(str, m[0:n])))
for i in range(n, len(m) - n):
	if i % n == n - 1:
		print(m[i])
		continue
	v = m[i]
	if i % n != 0 and m[i] > m[i + 1] and (m[i] > m[i - 1]) and (m[i] > m[i + n]) and (m[i] > m[i - n]):
		v = 'X'
	print(v, end='')
print(''.join(map(str, m[-n:])))


import sys
N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().strip())) for _ in range(N)]
for i in range(N):
	for j in range(N):
		if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
			print(A[i][j], end='')
		elif A[i][j] > A[i - 1][j] and A[i][j] > A[i + 1][j] and (A[i][j] > A[i][j - 1]) and (A[i][j] > A[i][j + 1]):
			print('X', end='')
		else:
			print(A[i][j], end='')
	print()


n = int(input())
m = [list(map(int, [c for c in input()])) for _ in range(n)]
for i in range(n):
	for j in range(n):
		if 0 < i < n - 1 and 0 < j < n - 1:
			is_cavity = True
			for ii in (-1, 0, 1):
				for jj in (-1, 0, 1):
					if 1 == abs(ii + jj) and ('X' == m[i + ii][j + jj] or m[i + ii][j + jj] >= m[i][j]):
						is_cavity = False
			if is_cavity:
				m[i][j] = 'X'
		print(m[i][j], end='')
	print()


import copy

def flatten(l):
	return [item for sublist in l for item in sublist]

class CavityMap:

	def __init__(self, size):
		self.depths = []
		self.size = size

	def __str__(self):
		string = ''
		for y in range(1, self.size + 1):
			string += ''.join(map(str, self.depths[y]))[1:-1] + '\n'
		return string[:-1]

	def __iter__(self):
		truncDepths = self.depths
		truncDepths.pop(0)
		truncDepths.pop()
		for line in truncDepths:
			line.pop(0)
			line.pop()
		return iter(flatten(truncDepths))

	def inputMap(self):
		self.depths.append([9 for _ in range(self.size)])
		for _ in range(self.size):
			line = [int(letter) for letter in input()]
			line.insert(0, 9)
			line.append(9)
			self.depths.append(line)
		self.depths.append([9 for _ in range(self.size)])

	def isCavity(self, row, col):
		return self.depths[row][col - 1] < self.depths[row][col] and self.depths[row][col + 1] < self.depths[row][col] and (self.depths[row - 1][col] < self.depths[row][col]) and (self.depths[row + 1][col] < self.depths[row][col])
cavities = CavityMap(int(input()))
cavities.inputMap()
depthsWithCavities = copy.deepcopy(cavities.depths)
for row in range(cavities.size):
	for col in range(cavities.size):
		if cavities.isCavity(row, col):
			depthsWithCavities[row][col] = 'X'
cavities.depths = copy.deepcopy(depthsWithCavities)
print(cavities)


n = int(input())
grid = [input() for i in range(n)]
for (i, x) in enumerate(grid):
	if i != 0 and i != n - 1:
		ans = ''
		for (j, y) in enumerate(x):
			if j != 0 and j != n - 1:
				if y > grid[i - 1][j] and y > grid[i][j - 1] and (y > grid[i + 1][j]) and (y > grid[i][j + 1]):
					ans += 'X'
				else:
					ans += y
			else:
				ans += y
		print(ans)
	else:
		print(x)


n = int(input())
grid = []
for i in range(n):
	grid.append(list(input()))
grid_temp = grid
if n > 2:
	for y in range(1, n - 1):
		for x in range(1, n - 1):
			adj = []
			for i in [-1, 1]:
				adj.append(grid[y][x + i])
				adj.append(grid[y + i][x])
			if grid[y][x] > max(adj):
				grid_temp[y][x] = 'X'
for i in range(n):
	print(''.join(grid_temp[i]))


n = int(input())
a = [list(map(int, input())) for i in range(n)]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if a[i][j] > max((x if x != 'X' else 10 for x in [a[i][j - 1], a[i][j + 1], a[i - 1][j], a[i + 1][j]])):
			a[i][j] = 'X'
print('\n'.join([''.join(map(str, line)) for line in a]))


def cavityMap(m, size):
	if size == 1 or size == 2:
		print(*m, sep='\n')
	else:
		print(m[0])
		for i in range(1, size - 1):
			print(m[i][0], end='')
			for j in range(1, size - 1):
				c = m[i][j]
				n = m[i - 1][j]
				s = m[i + 1][j]
				e = m[i][j + 1]
				w = m[i][j - 1]
				if c > n and c > s and (c > e) and (c > w):
					print('X', end='')
				else:
					print(c, end='')
			print(m[i][-1])
		print(m[-1])
n = int(input())
map_ = []
for i in range(n):
	map_.append(input())
cavityMap(map_, n)


n = int(input())
cavity_map = list()
for row in range(n):
	cavity_map.append([element for element in map(int, list(input()))])
for row in range(1, n - 1):
	for col in range(1, n - 1):
		if cavity_map[row][col] > cavity_map[row - 1][col] and cavity_map[row][col] > cavity_map[row + 1][col] and (cavity_map[row][col] > cavity_map[row][col - 1]) and (cavity_map[row][col] > cavity_map[row][col + 1]):
			cavity_map[row][col] = float('inf')
for row in range(n):
	for col in range(n):
		if cavity_map[row][col] == float('inf'):
			cavity_map[row][col] = 'X'
		else:
			cavity_map[row][col] = str(cavity_map[row][col])
	print(''.join(cavity_map[row]))


n = int(input())
A = []
B = []
for i in range(n):
	row = list(input())
	A.append([int(x) for x in row])
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if A[i][j] > max(A[i - 1][j], A[i + 1][j], A[i][j - 1], A[i][j + 1]):
			B.append((i, j))
for i in range(0, n):
	temprow = []
	for j in range(0, n):
		if (i, j) in B:
			temprow.append('X')
		else:
			temprow.append(A[i][j])
	print(''.join((str(x) for x in temprow)))


n = int(input())
_map = []
newmap = []
for line in range(n):
	_map.append([])
	nextCol = input()
	for col in nextCol:
		_map[line].append(col)
for line in range(n):
	newmap.append(_map[line][:])
for line in range(1, n - 1):
	for col in range(1, len(_map[line]) - 1):
		if _map[line][col] > _map[line][col - 1] and _map[line][col] > _map[line][col + 1] and (_map[line][col] > _map[line - 1][col]) and (_map[line][col] > _map[line + 1][col]):
			newmap[line][col] = 'X'
for line in newmap:
	for col in line:
		print(col, end='')
	print()


depthMap = []
for rowIndex in range(int(input())):
	depthMap.append([int(x) for x in input().strip()])
cavities = set()
for (y, row) in enumerate(depthMap):
	for (x, col) in enumerate(row):
		if 0 < y < len(depthMap) - 1 and 0 < x < len(row) - 1:
			neighbors = []
			if y > 0:
				neighbors.append((y - 1, x))
			if x < len(row) - 1:
				neighbors.append((y, x + 1))
			if y < len(depthMap) - 1:
				neighbors.append((y + 1, x))
			if x > 0:
				neighbors.append((y, x - 1))
			if all((depthMap[y2][x2] < depthMap[y][x] for (y2, x2) in neighbors)):
				cavities.add((y, x))
for (y, row) in enumerate(depthMap):
	for (x, col) in enumerate(row):
		if (y, x) in cavities:
			print('X', end='')
		else:
			print(depthMap[y][x], end='')
	print()


n = int(input())
ar = []
for _ in range(n):
	ar.append(list(input()))
for row in range(1, n - 1):
	for col in range(1, n - 1):
		if ar[row][col] > ar[row + 1][col] and ar[row][col] > ar[row - 1][col] and (ar[row][col] > ar[row][col + 1]) and (ar[row][col] > ar[row][col - 1]):
			ar[row][col] = 'X'
print('\n'.join((''.join(row) for row in ar)))


N = int(input())
cmap = []
for row in range(N):
	cmap.append(input())
for i in range(N - 2):
	for j in range(N - 2):
		if cmap[i + 1][j] < cmap[i + 1][j + 1] > cmap[i + 1][j + 2] and cmap[i][j + 1] < cmap[i + 1][j + 1] > cmap[i + 2][j + 1]:
			cmap[i + 1] = cmap[i + 1][:j + 1] + 'X' + cmap[i + 1][j + 2:]
for i in range(N):
	print(cmap[i])


def is_cavity(c_map, row, col):
	if row == 0 or col == 0:
		return False
	elif row == len(c_map) - 1 or col == len(c_map) - 1:
		return False
	elif c_map[row][col] > c_map[row - 1][col] and c_map[row][col] > c_map[row + 1][col] and (c_map[row][col] > c_map[row][col - 1]) and (c_map[row][col] > c_map[row][col + 1]):
		return True
	else:
		return False
num_inputs = int(input())
c_map = []
for i in range(num_inputs):
	c_map_row = input()
	c_map_row.split()
	c_map.append(c_map_row)
for i in range(num_inputs):
	for j in range(num_inputs):
		if is_cavity(c_map, i, j):
			print('X', end='')
		else:
			print(c_map[i][j], end='')
	print('\n', end='')


import copy

def get_input():
	N = int(input())
	str_grid = []
	for i in range(N):
		str_grid.append(list(input()))
	return [[int(c) for c in s] for s in str_grid]

def solve(grid):
	n = len(grid)
	cavities = copy.deepcopy(grid)
	for i in range(n):
		for j in range(n):
			if i != 0 and j != 0 and (i != n - 1) and (j != n - 1):
				cur = grid[i][j]
				if grid[i - 1][j] < cur and grid[i][j - 1] < cur and (grid[i][j + 1] < cur) and (grid[i + 1][j] < cur):
					cavities[i][j] = 'X'
	for i in range(n):
		print(''.join(map(str, cavities[i])))
solve(get_input())


import sys
T = int(input())
a = {}
for i in range(T):
	values = str(input())
	a[i] = []
	for value in values:
		a[i].append(value)
for x in range(1, T - 1):
	for y in range(1, T - 1):
		if a[x][y] > a[x - 1][y] and a[x][y] > a[x][y - 1] and (a[x][y] > a[x + 1][y]) and (a[x][y] > a[x][y + 1]):
			a[x][y] = 'X'
for x in range(T):
	for y in range(T):
		sys.stdout.write(a[x][y])
	sys.stdout.write('\n')


def is_cavity(i, j):
	for k in [-1, 1]:
		if area[i + k][j] >= area[i][j] or area[i][j + k] >= area[i][j]:
			return False
	return True
n = int(input())
area = [list(input()) for _ in range(n)]
output = [list(l) for l in area]
for i in range(1, n - 1):
	for j in range(1, n - 1):
		if is_cavity(i, j):
			output[i][j] = 'X'
print('\n'.join((''.join(l) for l in output)))