#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM =
            chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
void read(T& x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template <class T, class... Args>
void read(T& x, Args&... args) {
    read(x), read(args...);
}

template <class T>
void write(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

const int MAXN = 501;
const int MOD = 1E9 + 7;
int n, m;
char c[MAXN][MAXN];

LL qpow(LL a, LL b, LL MOD) {
    LL ans = 1, base = a;
    while (b) {
        if (b & 1) ans = ans * base % MOD;
        b >>= 1, base = base * base % MOD;
    }
    return ans;
}

void solve(int caseNum) {
    // type your code here
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) cin >> c[i][j];
    if (m % 3 == 0 || m % 3 == 2) {
        for (int j = 2; j <= m; j += 3)
            for (int i = 1; i <= n; i++) c[i][j] = 'X';
        for (int j = 1, tag = 1; j <= m; j++) {
            if (j % 3 == 2) {
                if (tag)
                    for (int k = j - 1; k >= j - 2 && k >= 1; k--)
                        c[1][k] = 'X';
                tag = 1;
                continue;
            }
            if (!tag) continue;
            for (int i = 1; i <= n; i++) {
                if (c[i][j] == 'X') {
                    if (j % 3 == 0) {
                        c[i][j + 1] = 'X';
                        tag = 0;
                        break;
                    } else {
                        c[i][j - 1] = 'X';
                        tag = 0;
                        break;
                    }
                }
            }
        }
    } else {
        for (int j = 1; j <= m; j += 3)
            for (int i = 1; i <= n; i++) c[i][j] = 'X';
        for (int j = 1, tag = 1; j <= m; j++) {
            if (j % 3 == 1) {
                if (tag)
                    for (int k = j - 1; k >= j - 2 && k >= 1; k--)
                        c[1][k] = 'X';
                tag = 1;
                continue;
            }
            if (!tag) continue;
            for (int i = 1; i <= n; i++) {
                if (c[i][j] == 'X') {
                    if (j % 3 == 2) {
                        c[i][j + 1] = 'X';
                        tag = 0;
                        break;
                    } else {
                        c[i][j - 1] = 'X';
                        tag = 0;
                        break;
                    }
                }
            }
        }
    }
    for (int i = 1; i <= n; i++, cout << endl)
        for (int j = 1; j <= m; j++) cout << c[i][j];
}

signed main() {
    // freopen("1.in", "r", stdin);
    int testCase = 1;
    // read(testCase);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> testCase;
    for (int i = 1; i <= testCase; i++) solve(i);
    return 0;
}