#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 1000000007;
 
ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}
 
ll inverse(ll n){
	return power(n, MOD-2);
}
 
ll add(ll a, ll b){
	return (a+b) % MOD;
}

ll mul(ll a, ll b){
	return (a*b) % MOD;
}

int a[4] = {0, 0, 1, -1};
int b[4] = {1, -1, 0, 0};
int main(){
	ios::sync_with_stdio(false);
	int TC; cin >> TC;
	while (TC--){
		int n, m; cin >> n >> m;
		int used[n][m]; ms(used, 0, sizeof(used));
		vector<string> s(n);
		FOR(i, 0, n) cin >> s[i];
		for (int i = 0; i < n; i+=3){
			if (i % 3 == 0){
				FOR(j, 0, m) s[i][j] = 'X';
			}
			if (i != 0){
				bool sol = true;
				FOR(j, 0, m){
					if (s[i-1][j] == 'X' || s[i-2][j] == 'X'){
						sol = false;
						s[i-1][j] = 'X'; s[i-2][j] = 'X';
						break;
					}
				}
				if (sol){
					s[i-1][0] = 'X'; s[i-2][0] = 'X';
				}
			}
		}
		if (n % 3 == 0){
			FOR(j, 0, m){
				if (s[n-1][j] == 'X' || s[n-2][j] == 'X'){
					s[n-1][j] = 'X'; s[n-2][j] = 'X';
				}
			}
		}
		FOR(i, 0, n) cout << s[i] << '\n';
	}
	return 0;
}



