There are many sunflowers in the Garden of the Sun.

Garden of the Sun is a rectangular table with n rows and m columns, where the cells of the table are farmlands. All of the cells grow a sunflower on it. Unfortunately, one night, the lightning stroke some (possibly zero) cells, and sunflowers on those cells were burned into ashes. In other words, those cells struck by the lightning became empty. Magically, any two empty cells have no common points (neither edges nor corners).

Now the owner wants to remove some (possibly zero) sunflowers to reach the following two goals: 

  * When you are on an empty cell, you can walk to any other empty cell. In other words, those empty cells are connected. 
  * There is exactly one simple path between any two empty cells. In other words, there is no cycle among the empty cells. 



You can walk from an empty cell to another if they share a common edge.

Could you please give the owner a solution that meets all her requirements?

Note that you are not allowed to plant sunflowers. You don't need to minimize the number of sunflowers you remove. It can be shown that the answer always exists.

Input

The input consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases. The description of the test cases follows.

The first line contains two integers n, m (1 ≤ n,m ≤ 500) — the number of rows and columns. 

Each of the next n lines contains m characters. Each character is either 'X' or '.', representing an empty cell and a cell that grows a sunflower, respectively.

It is guaranteed that the sum of n ⋅ m for all test cases does not exceed 250 000.

Output

For each test case, print n lines. Each should contain m characters, representing one row of the table. Each character should be either 'X' or '.', representing an empty cell and a cell with a sunflower, respectively.

If there are multiple answers, you can print any. It can be shown that the answer always exists.

Example

Input


5
3 3
X.X
...
X.X
4 4
....
.X.X
....
.X.X
5 5
.X...
....X
.X...
.....
X.X.X
1 10
....X.X.X.
2 2
..
..


Output


XXX
..X
XXX
XXXX
.X.X
.X..
.XXX
.X...
.XXXX
.X...
.X...
XXXXX
XXXXXXXXXX
..
..

Note

Let's use (x,y) to describe the cell on x-th row and y-th column.

In the following pictures white, yellow, and blue cells stand for the cells that grow a sunflower, the cells lightning stroke, and the cells sunflower on which are removed, respectively.

<image>

In the first test case, one possible solution is to remove sunflowers on (1,2), (2,3) and (3 ,2). 

<image>

Another acceptable solution is to remove sunflowers on (1,2), (2,2) and (3,2). 

<image>

This output is considered wrong because there are 2 simple paths between any pair of cells (there is a cycle). For example, there are 2 simple paths between (1,1) and (3,3).

  1. (1,1)→ (1,2)→ (1,3)→ (2,3)→ (3,3)

  2. (1,1)→ (2,1)→ (3,1)→ (3,2)→ (3,3) 



<image>

This output is considered wrong because you can't walk from (1,1) to (3,3).

Difficulty: HARD
Tags: Graph algorithms

Constructive algorithms

Starter code:

Solutions:
import sys, os
if os.environ['USERNAME'] == 'kissz':
	inp = open('in.txt', 'r').readline

	def debug(*args):
		print(*args, file=sys.stderr)
else:
	inp = sys.stdin.readline

	def debug(*args):
		pass
for _ in range(int(inp())):
	(n, m) = map(int, inp().split())
	R = []
	for i in range(n):
		R += [list(inp().strip())]
	n_ = (n - 1) // 3 * 3 + 1
	n__ = n - n_
	for i in range(n_):
		if i % 3 == 0:
			R[i] = ['X'] * m
		elif i % 3 == 1:
			if 'X' in R[i]:
				j = R[i].index('X')
				R[i + 1][j] = 'X'
			elif 'X' in R[i + 1]:
				j = R[i + 1].index('X')
				R[i][j] = 'X'
			else:
				R[i][0] = 'X'
				R[i + 1][0] = 'X'
	if n__ == 2:
		for j in range(m):
			if R[-1][j] == 'X':
				R[-2][j] = 'X'
	for i in range(n):
		print(''.join(R[i]))


import os, sys, heapq as h, time
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def getInt():
	return int(input())

def getStrs():
	return input().split()

def getInts():
	return list(map(int, input().split()))

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 10 ** 9 + 7

def solve():
	(N, M) = getInts()
	grid = [listStr() for _ in range(N)]
	start = 0 if N % 3 == 1 else 1
	for i in range(start, N, 3):
		for j in range(M):
			grid[i][j] = 'X'
		if i + 2 > N - 1:
			break
		flag = False
		for j in range(M):
			if grid[i + 1][j] == 'X' or grid[i + 2][j] == 'X':
				flag = True
				grid[i + 1][j] = 'X'
				grid[i + 2][j] = 'X'
				break
		if not flag:
			grid[i + 1][0] = 'X'
			grid[i + 2][0] = 'X'
	for g in grid:
		print(*g, sep='')
	return
for _ in range(getInt()):
	solve()


import sys, io, os
try:
	Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
	Z = lambda : sys.stdin.readline().encode()
O = []
for _ in range(int(Z())):
	(N, M) = map(int, Z().split())
	b = []
	w = [[''] * M for i in range(N)]
	s = M % 3 == 0
	t = 2 - s - s
	for i in range(N):
		b.append([*Z().strip()])
	if M < 2:
		O.append('\n'.join(['X'] * N))
		continue
	if N < 2:
		O.append('X' * M)
		continue
	for m in range(M):
		v = m % 3
		if v == s:
			for n in range(N):
				w[n][m] = 'X'
		elif m and v == t:
			for n in range(N):
				w[n][m] = chr(b[n][m])
			if b[1][m - 1] == 88 or b[1][m] == 88:
				w[1][m - 1] = 'X'
				w[1][m] = 'X'
			else:
				w[0][m - 1] = 'X'
				w[0][m] = 'X'
		else:
			for n in range(N):
				w[n][m] = chr(b[n][m])
	O.append('\n'.join((''.join(i) for i in w)))
print('\n'.join(O))


def solve(n, m):
	empty = 'X'
	emptyall = [empty] * m
	grid = []
	for i in range(n):
		grid.append(list(input()))
	if n % 3 == 1:
		for i in range(n):
			if i % 3 == 0:
				grid[i] = emptyall
			elif i % 3 == 2:
				if empty in grid[i - 1] or empty in grid[i]:
					for j in range(m):
						if grid[i][j] == empty:
							grid[i - 1][j] = empty
							break
						elif grid[i - 1][j] == empty:
							grid[i][j] = empty
							break
				else:
					grid[i - 1][0] = empty
					grid[i][0] = empty
	else:
		for i in range(1, n):
			if i % 3 == 1:
				grid[i] = emptyall
			elif i % 3 == 0:
				if empty in grid[i - 1] or empty in grid[i]:
					for j in range(m):
						if grid[i][j] == empty:
							grid[i - 1][j] = empty
							break
						elif grid[i - 1][j] == empty:
							grid[i][j] = empty
							break
				else:
					grid[i - 1][0] = empty
					grid[i][0] = empty
	for i in range(n):
		print(''.join(grid[i]))
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	solve(n, m)


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
	(n, m) = rl()
	a = [[c for c in stdin.readline().rstrip()] for _ in range(n)]
	base = 0 if n % 3 == 1 else 1
	for y in range(n):
		if y % 3 == base:
			a[y] = ['X'] * m
		else:
			if (y - base) % 3 == 1:
				y2 = y + 1
			else:
				y2 = y - 1
			if m > 1 and (a[y][1] == 'X' or (y2 >= 0 and y2 <= n - 1 and (a[y2][1] == 'X'))):
				a[y][1] = 'X'
			else:
				a[y][0] = 'X'
	for line in a:
		print(''.join(line))


def main():
	T = int(input())
	for c in range(T):
		inp = input().rstrip().split(' ')
		(n, m) = (int(inp[0]), int(inp[1]))
		mat = []
		for _ in range(n):
			mat.append(list(input().rstrip()))
		if n == 1 or n == 2:
			for j in range(m):
				mat[0][j] = 'X'
		else:
			i = 0
			pending = False
			while i < n:
				if i == 0:
					pass
				elif i % 3 == 1:
					for j in range(m):
						mat[i][j] = 'X'
					pending = True
				elif i % 3 == 2:
					for j in range(m):
						if pending and mat[i][j] == 'X' and (i + 1 < n):
							mat[i + 1][j] = 'X'
							pending = False
				else:
					for j in range(m):
						if pending and mat[i][j] == 'X':
							mat[i - 1][j] = 'X'
							pending = False
					if pending:
						mat[i - 1][0] = 'X'
						mat[i][0] = 'X'
						pending = False
				i += 1
			if n % 3 == 1:
				for j in range(m):
					if mat[-1][j] == 'X':
						mat[-2][j] = 'X'
		for row in mat:
			print(''.join(row))
main()


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	s = [['' for _ in range(n)] for _ in range(m)]
	for i in range(m):
		s[i] = [_ for _ in input()]
	if m % 3 == 1:
		for i in range(0, m, 3):
			for j in range(n):
				s[i][j] = 'X'
		for i in range(1, m - 1, 3):
			if s[i].count('X') == 0 and s[i + 1].count('X') == 0:
				s[i][0] = s[i + 1][0] = 'X'
			elif s[i].count('X') == 0:
				s[i][s[i + 1].index('X')] = 'X'
			else:
				s[i + 1][s[i].index('X')] = 'X'
	else:
		for i in range(1, m, 3):
			for j in range(n):
				s[i][j] = 'X'
		for i in range(2, m - 1, 3):
			if s[i].count('X') == 0 and s[i + 1].count('X') == 0:
				s[i][0] = s[i + 1][0] = 'X'
			elif s[i].count('X') == 0:
				s[i][s[i + 1].index('X')] = 'X'
			else:
				s[i + 1][s[i].index('X')] = 'X'
	for i in range(m):
		for j in range(n):
			print(s[i][j], end='')
		print()


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		board = []
		newBoard = []
		for _ in range(n):
			board.append(input())
			newBoard.append([])
			for elem in board[_]:
				newBoard[_].append('X' if elem == 'X' else '.')
		if n % 3:
			for i in range(n // 3 + 1):
				for j in range(m):
					newBoard[3 * i][j] = 'X'
				if i < n // 3:
					flag = False
					for j in range(m):
						if newBoard[3 * i + 1][j] == 'X' or newBoard[3 * i + 2][j] == 'X':
							flag = True
							newBoard[3 * i + 1][j] = 'X'
							newBoard[3 * i + 2][j] = 'X'
							break
					if not flag:
						newBoard[3 * i + 1][0] = 'X'
						newBoard[3 * i + 2][0] = 'X'
		else:
			for i in range(n // 3):
				for j in range(m):
					newBoard[3 * i + 1][j] = 'X'
				if i < n // 3 - 1:
					flag = False
					for j in range(m):
						if newBoard[3 * i + 2][j] == 'X' or newBoard[3 * i + 3][j] == 'X':
							flag = True
							newBoard[3 * i + 2][j] = 'X'
							newBoard[3 * i + 3][j] = 'X'
							break
					if not flag:
						newBoard[3 * i + 2][0] = 'X'
						newBoard[3 * i + 3][0] = 'X'
		for row in newBoard:
			print(''.join(row))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import io
import os

def solve(R, C, grid):
	grid = [list(row) for row in grid]
	for r in range(0, R, 3):
		for c in range(C):
			grid[r][c] = 'X'
	for r in range(0, R, 3):
		if r + 3 < R:
			for c in range(C):
				if grid[r + 1][c] == 'X' or grid[r + 2][c] == 'X':
					assert (grid[r + 1][c] == 'X') ^ (grid[r + 2][c] == 'X')
					grid[r + 1][c] = 'X'
					grid[r + 2][c] = 'X'
					break
			else:
				assert grid[r + 1][0] != 'X'
				assert grid[r + 2][0] != 'X'
				grid[r + 1][0] = 'X'
				grid[r + 2][0] = 'X'
	if R % 3 == 0:
		for c in range(C):
			if grid[-1][c] == 'X':
				assert grid[-3][c] == 'X'
				assert grid[-2][c] != 'X'
				grid[-2][c] = 'X'
	return '\n'.join((''.join(row) for row in grid))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, M) = [int(x) for x in input().split()]
	grid = [input().decode().rstrip() for i in range(N)]
	ans = solve(N, M, grid)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m) = map(int, input().split())
	MAP = [list(input().strip()) for i in range(n)]
	if m <= 1:
		for i in range(n):
			MAP[i][0] = 'X'
	for j in range(1, m, 3):
		for i in range(n):
			MAP[i][j] = 'X'
	for j in range(2, m, 3):
		if j + 1 < m:
			for i in range(n):
				if MAP[i][j] == 'X':
					MAP[i][j + 1] = 'X'
					break
			else:
				for i in range(n):
					if MAP[i][j + 1] == 'X':
						MAP[i][j] = 'X'
						break
				else:
					MAP[0][j] = MAP[0][j + 1] = 'X'
	if m % 3 == 1:
		for i in range(n):
			if MAP[i][m - 1] == 'X':
				MAP[i][m - 2] = 'X'
	for i in range(n):
		print(''.join(MAP[i]))


from sys import stdin, stdout
from collections import defaultdict
import math

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, m) = list(map(int, stdin.readline().split()))
		arr = []
		for _ in range(n):
			arr.append([x for x in stdin.readline().strip()])
		if m == 1:
			for _ in range(n):
				stdout.write('X\n')
			continue
		if n == 1:
			ans = 'X' * m
			stdout.write(ans + '\n')
			continue
		for row in range(1, n, 3):
			for j in range(m):
				arr[row][j] = 'X'
		for row in range(3, n, 3):
			is_marked = False
			for j in range(m):
				if arr[row][j] == 'X':
					arr[row - 1][j] = 'X'
					is_marked = True
					break
				if arr[row - 1][j] == 'X':
					arr[row][j] = 'X'
					is_marked = True
					break
			if is_marked:
				continue
			arr[row][0] = 'X'
			arr[row - 1][0] = 'X'
		if (n - 1) % 3 == 0:
			for j in range(m):
				if arr[n - 1][j] == 'X':
					arr[row - 1][j] = 'X'
		for i in range(n):
			stdout.write(''.join(arr[i]) + '\n')
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve(n, m):
	empty = 'X'
	emptyall = [empty] * m
	grid = []
	for i in range(n):
		grid.append(list(input()))
	if n % 3 == 1:
		for i in range(n):
			if i % 3 == 0:
				grid[i] = emptyall
			elif i % 3 == 2:
				if empty in grid[i - 1] or empty in grid[i]:
					for j in range(m):
						if grid[i][j] == empty:
							grid[i - 1][j] = empty
							break
						elif grid[i - 1][j] == empty:
							grid[i][j] = empty
							break
				else:
					grid[i - 1][0] = empty
					grid[i][0] = empty
	else:
		for i in range(1, n):
			if i % 3 == 1:
				grid[i] = emptyall
			elif i % 3 == 0:
				if empty in grid[i - 1] or empty in grid[i]:
					for j in range(m):
						if grid[i][j] == empty:
							grid[i - 1][j] = empty
							break
						elif grid[i - 1][j] == empty:
							grid[i][j] = empty
							break
				else:
					grid[i - 1][0] = empty
					grid[i][0] = empty
	for i in range(n):
		print(''.join(grid[i]))
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	solve(n, m)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for _ in range(n):
		grid.append(list(input()))
	if n % 3 != 0:
		for i in range(0, n, 3):
			for j in range(m):
				grid[i][j] = 'X'
		for i in range(0, n - 3, 3):
			if m == 1 or (grid[i + 1][1] != 'X' and grid[i + 2][1] != 'X'):
				grid[i + 1][0] = 'X'
				grid[i + 2][0] = 'X'
			else:
				grid[i + 1][1] = 'X'
				grid[i + 2][1] = 'X'
	else:
		for i in range(0, n, 3):
			for j in range(m):
				grid[i + 1][j] = 'X'
		for i in range(1, n - 3, 3):
			if m == 1 or (grid[i + 1][1] != 'X' and grid[i + 2][1] != 'X'):
				grid[i + 1][0] = 'X'
				grid[i + 2][0] = 'X'
			else:
				grid[i + 1][1] = 'X'
				grid[i + 2][1] = 'X'
	for i in range(n):
		print(''.join(grid[i]))


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	s = [list(stdin.readline()[:-1]) for i in range(n)]
	if n % 3 != 0:
		for i in range(0, n, 3):
			for j in range(m):
				s[i][j] = 'X'
		for i in range(1, n, 3):
			if i + 1 >= n:
				continue
			if m > 1 and (s[i][1] == 'X' or s[i + 1][1] == 'X'):
				s[i][1] = 'X'
				s[i + 1][1] = 'X'
			else:
				s[i][0] = 'X'
				s[i + 1][0] = 'X'
		for i in s:
			print(''.join(i))
	else:
		for i in range(1, n, 3):
			for j in range(m):
				s[i][j] = 'X'
		for i in range(2, n, 3):
			if i + 1 >= n:
				continue
			if m > 1 and (s[i][1] == 'X' or s[i + 1][1] == 'X'):
				s[i][1] = 'X'
				s[i + 1][1] = 'X'
			else:
				s[i][0] = 'X'
				s[i + 1][0] = 'X'
		for i in s:
			print(''.join(i))


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.readline

	def print_(grid):
		for line in grid:
			print(''.join(line))
	for _ in range(int(input())):
		(H, W) = map(int, input().split())
		grid = [['.'] * W for _ in range(H)]
		for h in range(H):
			line = input().rstrip('\n')
			for w in range(W):
				grid[h][w] = line[w]
		if H == 1:
			print('X' * W)
			continue
		elif H == 2:
			for w in range(W):
				grid[0][w] = 'X'
			print_(grid)
			continue
		elif H == 3:
			for w in range(W):
				grid[1][w] = 'X'
			print_(grid)
			continue
		if W == 1:
			for h in range(H):
				grid[h][0] = 'X'
			print_(grid)
			continue
		elif W == 2:
			for h in range(H):
				grid[h][0] = 'X'
			print_(grid)
			continue
		elif W == 3:
			for h in range(H):
				grid[h][1] = 'X'
			print_(grid)
			continue
		for h in range(H):
			if h % 3 == 0:
				for w in range(W):
					grid[h][w] = 'X'
		for h in range(H):
			if h % 3 == 2:
				flg = 0
				for w in range(W):
					if grid[h][w] == 'X' or grid[h - 1][w] == 'X':
						flg = 1
						grid[h][w] = 'X'
						grid[h - 1][w] = 'X'
						break
				if not flg:
					grid[h][0] = 'X'
					grid[h - 1][0] = 'X'
		if H % 3 == 0:
			for w in range(W):
				if grid[H - 1][w] == 'X' or grid[H - 2][w] == 'X':
					grid[H - 1][w] = 'X'
					grid[H - 2][w] = 'X'
		print_(grid)
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = [list(input()[:-1]) for _ in range(n)]
	if n % 3 == 0:
		for i in range(1, n, 3):
			cnt = 0
			for j in range(m):
				s[i][j] = 'X'
				if i < n - 2 and cnt == 0:
					if s[i + 1][j] == 'X':
						s[i + 2][j] = 'X'
						cnt += 1
					elif s[i + 2][j] == 'X':
						s[i + 1][j] = 'X'
						cnt += 1
			if i < n - 2 and cnt == 0:
				s[i + 1][j] = 'X'
				s[i + 2][j] = 'X'
	else:
		for i in range(0, n, 3):
			cnt = 0
			for j in range(m):
				s[i][j] = 'X'
				if i < n - 2 and cnt == 0:
					if s[i + 1][j] == 'X':
						s[i + 2][j] = 'X'
						cnt += 1
					elif s[i + 2][j] == 'X':
						s[i + 1][j] = 'X'
						cnt += 1
			if i < n - 2 and cnt == 0:
				s[i + 1][j] = 'X'
				s[i + 2][j] = 'X'
	for row in s:
		print(''.join(row))


import sys, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def solve_(mrr):
	if OFFLINE_TEST:
		for r in mrr:
			log(r)
	row_to_list = defaultdict(list)
	for (i, row) in enumerate(mrr):
		for (j, cell) in enumerate(row):
			if cell == 'X':
				row_to_list[i].append(j)
	xrr = [list(row) for row in mrr]
	if len(xrr[0]) <= 2 and len(xrr) <= 2:
		return xrr
	offset = 1
	if len(xrr) % 3 == 1:
		offset = 0
	allpillars = []
	for (i, row) in enumerate(xrr):
		if i % 3 == offset:
			xrr[i] = ['X'] * len(xrr[0])
			allpillars.append(i)
		elif i == 0 or i == len(xrr) - 1:
			continue
	log(allpillars)
	for (a, b) in zip(allpillars, allpillars[1:]):
		if row_to_list[a + 1]:
			xrr[a + 2][row_to_list[a + 1][0]] = 'X'
		elif row_to_list[b - 1]:
			xrr[b - 2][row_to_list[b - 1][0]] = 'X'
		else:
			xrr[a + 1][0] = 'X'
			xrr[b - 1][0] = 'X'
	return xrr
for case_num in range(int(input())):
	(k, _) = list(map(int, input().split()))
	arr = read_strings(k)
	res = solve(arr)
	res = '\n'.join([''.join(r) for r in res])
	print(res)


from sys import stdin, stdout

def garden_of_the_sun(n, m, s_a):
	if m == 1:
		for i in range(n):
			s_a[i][0] = 'X'
		return s_a
	j = 1
	while j < m:
		for i in range(n):
			s_a[i][j] = 'X'
		j += 3
	j = 3
	while j < m - 1:
		found = False
		for i in range(n):
			if s_a[i][j] == 'X':
				s_a[i][j - 1] = 'X'
				found = True
				break
			if s_a[i][j - 1] == 'X':
				s_a[i][j] = 'X'
				found = True
				break
		if not found:
			s_a[0][j] = 'X'
			s_a[0][j - 1] = 'X'
		j += 3
	if j == m - 1:
		for i in range(n):
			if s_a[i][j] == 'X':
				s_a[i][j - 1] = 'X'
	return s_a
t = int(stdin.readline())
for _ in range(t):
	(n, m) = map(int, stdin.readline().split())
	s_a = []
	for _ in range(n):
		s_a.append(list(stdin.readline().strip()))
	r_a = garden_of_the_sun(n, m, s_a)
	for i in range(n):
		stdout.write(''.join(r_a[i]) + '\n')