#include<bits/stdc++.h>
using namespace std;

int n,m,Min[505];
char ch[505][505];

inline void solve()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) Min[i]=m;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) {
			char c=getchar();
			while (isspace(c)) c=getchar();
			ch[i][j]=c;
			if (c=='X') Min[i]=min(Min[i],j);
		}
	for (int i=1;i<=n;i+=3) {
		for (int j=1;j<=m;j++) ch[i][j]='X';
		if (i+3<=n) {
			int cur=min(Min[i+1],Min[i+2]);
			ch[i+1][cur]=ch[i+2][cur]='X';
		}
		if (i+2==n) {
			for (int j=1;j<=m;j++) {
				if (ch[i+2][j]=='X')
					ch[i+1][j]='X';
			}
		}
	}
	for (int i=1;i<=n;i++,puts(""))
		for (int j=1;j<=m;j++) putchar(ch[i][j]);	
}
int main()
{
	int t;
	scanf("%d",&t);
	for (int i=1;i<=t;i++) {
		solve();
	}
}