#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(i=a;i<=b;++i)
using namespace std;
const int N=505;
int n,m,i,j,fl,T;
char st[N][N];
int main(){
	//freopen("B.in","r",stdin);
	scanf("%d",&T);
	while (T--){
		scanf("%d %d",&n,&m);
		fo(i,1,n) scanf("%s",st[i]);
		for(i=2;i<=n;i+=3) 
			fo(j,0,m-1) st[i][j]='X';
		if (n==1) 
			fo(j,0,m-1) st[1][j]='X';
		fo(i,4,n) {
			if (i%3!=1) continue;
			fl=0;
			fo(j,0,m-1)
			  if (st[i][j]=='X'||st[i-1][j]=='X') {
			  	  if (fl) continue;
			  	  st[i][j]='X';
				  st[i-1][j]='X';
			  	  if (i!=n) fl=1;
			  }
			if (!fl&&i!=n)   st[i][0]=st[i-1][0]='X';	
		}
		fo(i,1,n) printf("%s\n",st[i]);
	}
} 
