#include<bits/stdc++.h>
#define mp make_pair
const int maxn=6e2+5;
const int maxm=maxn*maxn;
const int inf=1e9;
using namespace std;
int t,n,m;
char s[maxn][maxn];
void work(int x){
	for(int i=x;i<=m;i+=3)
		for(int j=1;j<=n;j++)s[j][i]='X';
	for(int i=x+1,j=x+2;j<=m;i+=3,j+=3){
		for(int k=1;k<=n;k++){
			if(s[k-1][i]!='X'&&s[k+1][i]!='X'&&s[k-1][j]!='X'&&s[k+1][j]!='X'){
				s[k][i]=s[k][j]='X';
				break;
			}
		}
	}
}
int main(){
	//freopen("1.out","w",stdout);
	scanf("%d",&t);
	for(;t;t--){
		scanf("%d %d",&n,&m);
		for(int i=0;i<=n+1;i++)for(int j=0;j<=m+1;j++)s[i][j]='.';
		for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
		if(m%3==0||m%3==2)work(2);
		else work(1);
		for(int i=1;i<=n;i++,puts("")){
			for(int j=1;j<=m;j++)printf("%c",s[i][j]);
		}
	}
	return 0;
}
