#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

#define forsn(i,s,n) for(int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for(int i = (n) - 1;i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)

int firstOnRow(vector<string>& b, int row) {
	forn(i, b[row].size()){
		if (b[row][i] == 'X') return i;
	}
	return -1;
}

int main() {
	int t; cin >> t;
	
	while (t--) {
		int n,m; cin >> n >> m;
		
		vector<string> b;
		forn(i, n) {
			string s;
			cin >> s;
			b.push_back(s);
		}
		
		for (int i = 0;i < n;i += 3) {
			forn(j, m) b[i][j] = 'X';
			
			if (i + 3 < n) {
				if (firstOnRow(b, i + 1) != -1) {
					b[i + 2][firstOnRow(b, i + 1)] = 'X';
				} else if (firstOnRow(b, i + 2) != -1) {
					b[i + 1][firstOnRow(b, i + 2)] = 'X';
				} else {
					b[i + 1][0] = 'X';
					b[i + 2][0] = 'X';
				}
			}
		}
		if (n % 3 == 0) {
			forn(i, m) if (b[n - 1][i] == 'X') b[n - 2][i] = 'X';
		}
		
		forn(i,n) cout << b[i] << '\n';
	}
}
