#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;
const int MAXN=5005;

int T,N,M;char S[MAXN][MAXN];
namespace CHECK{
	bool flag=0,vis[MAXN][MAXN];int qwq,cnt;
	void dfs(int x,int y,int xt,int yt){
		if(flag)return;
		if(x>N||y>M||x<1||y<1||S[x][y]!='X')return;
		//printf("dfs(%d,%d,%d,%d),flag=%d\n",x,y,xt,yt,flag);
		if(vis[x][y]){flag=1;return;}
		++qwq,vis[x][y]=1;
		if(x+1!=xt||y!=yt)dfs(x+1,y,x,y);
		if(x!=xt||y+1!=yt)dfs(x,y+1,x,y);
		if(x-1!=xt||y!=yt)dfs(x-1,y,x,y);
		if(x!=xt||y-1!=yt)dfs(x,y-1,x,y);
	}
	void check(){
		//S[1][2]='X';
		flag=0,qwq=cnt=0;
		for(int i=1;i<=N;++i)for(int j=1;j<=M;++j){
			if(S[i][j]=='X')++cnt;
			vis[i][j]=0;
		}
		for(int i=1;i<=N;++i)for(int j=1;j<=M;++j)if(S[i][j]=='X'){
			dfs(i,j,0,0);
			if(qwq!=cnt)puts("Wrong answer 1");
			if(flag)puts("Wrong answer 2");
			return;
		}
	}
};
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&N,&M);
		if(N%3==0){
			for(int i=1;i<=N;++i){
				scanf("%s",S[i]+1);
				if(i%3==2){for(int j=1;j<=M;++j)S[i][j]='X';}
				else if(i%3==1&&i>1){
					bool flag=0;
					for(int j=1;j<=M;++j){
						if(S[i-1][j]=='X'){S[i][j]='X',flag=1;break;}
						if(S[i][j]=='X'){S[i-1][j]='X',flag=1;break;}
					}
					if(!flag)S[i-1][1]=S[i][1]='X';
				}
			}
		}else{
			for(int i=1;i<=N;++i){
				scanf("%s",S[i]+1);
				if(i%3==1){for(int j=1;j<=M;++j)S[i][j]='X';}
				else if(i%3==0){
					bool flag=0;
					for(int j=1;j<=M;++j){
						if(S[i-1][j]=='X'){S[i][j]='X',flag=1;break;}
						if(S[i][j]=='X'){S[i-1][j]='X',flag=1;break;}
					}
					if(!flag)S[i-1][1]=S[i][1]='X';
				}
			}
		}
		//CHECK::check();
		for(int i=1;i<=N;++i)puts(S[i]+1);
	}
	return 0;
}