#include<bits/stdc++.h>
using namespace std;
#define ll long long
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
template<class T> inline void read(T &n){
	char ch=GC;T w=1,x=0;
	while(!isdigit(ch)){if(ch=='-') w=-1;ch=GC;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=GC;}
	n=x*w;
}
int T, n, m;
char Map[505][505];
void solve() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%s", Map[i] + 1);
	for(int i = 1; i <= n; i += 3) {
		for(int j = 1; j <= m; j++) Map[i][j] = 'X';
		if(i + 2 > n) break;
		int cc = 0;
		for(int j = 1; j <= m; j++)
			if(Map[i + 2][j] == 'X') {
				if(i + 3 > n) Map[i + 1][j] = 'X';
				else {
					if(cc == 0) Map[i + 1][j] = 'X', cc++;
				}
			}
		if(i + 3 <= n && cc == 0) {
			for(int j = 1; j <= m; j++)
				if(Map[i + 1][j] == 'X') {
					Map[i + 2][j] = 'X', cc++;
					break;
				}
			if(cc == 0) Map[i + 1][1] = Map[i + 2][1] = 'X';
		}
		
	}
	for(int i = 1; i <= n; i++, putchar('\n'))
		for(int j = 1; j <= m; j++) putchar(Map[i][j]);
}
int main(){
	cin >> T;
	while(T--) solve();
	return 0;
}
