#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<queue>
#include<cmath>
#include<deque>
#include<stack>
#include<iomanip>
#include<random>
#include<cstdio>
#include<string>
#include<cstring>
#include<fstream>
#include<numeric>
#include<bitset>
#include<cassert>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(30);
    int _ = 1;
    cin >> _;
    while (_--) {
        int n, m;
        cin >> n >> m;
        vector<vector<bool>> a(n, vector<bool>(m));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                char c;
                cin >> c;
                a[i][j] = c - '.';
                if (i % 3 == 1 || n == 1) {
                    a[i][j] = true;
                }
            }
        }
        for (int i = 2; i + 2 <= n; i += 3) {
            if (i + 2 == n) {
                for (int j = 0; j < m; j++) {
                    if (a[i][j] || a[i + 1][j]) {
                        a[i][j] = a[i + 1][j] = true;
                    }
                }
                continue;
            }
            int pos = 0;
            for (int j = 0; j < m; j++) {
                if (a[i][j] || a[i + 1][j]) {
                    pos = j;
                    break;
                }
            }
            a[i][pos] = a[i + 1][pos] = true;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << (a[i][j] ? "X" : ".");
            }
            cout << endl;
        }
    }
}
/*
1
5 5
X.X.X
.....
X.X.X
.....
X.X.X
*/