#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int T, n, m; cin >> T; while(T--) {
		cin >> n >> m;
		string g[n];
		for(auto &i: g) cin >> i;
		for(int i = n % 3 == 0; i < n; i += 3) {
			g[i] = string(m, 'X');
			if(i + 2 < n) {
				int p = 0;
				for(int j = 1; j < m; j++) {
					if(g[i + 1][j] == 'X' || g[i + 2][j] == 'X') p = j;
				}
				g[i + 1][p] = g[i + 2][p] = 'X';
			}
		}
		for(auto i: g) cout << i << "\n";
	}
}
