
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x.size()))
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
const int N = 510;
int T;
char s[N][N];
int n, m;
void solve() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n) scanf("%s", s[i]);
	for(int i = 1; i < n; i += 3) {
		rep(j, 0, m) s[i][j] = 'X';
		if (i >= 3) {
			int t = -1;
			rep(j, 0, m) if (s[i - 1][j] == 'X' || s[i - 2][j] == 'X') t = j;
			if (-1 == t) t = 0;
			s[i - 1][t] = s[i - 2][t] = 'X';
		}
	}
	if (n == 1) 
		rep(i, 0, m) s[0][i] = 'X';
	else if (n % 3 == 1){
		rep(j, 0, m) if (s[n - 1][j] == 'X') s[n - 2][j] = 'X';
	}
	rep(i, 0, n) puts(s[i]);
}
int main() {
	scanf("%d", &T);
	rep(cas, 0, T) {
		solve();
	}
	return 0;
}
