#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

#define MULTIPLE_CASES

void solve(int tc = 0)
{
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    int f = (n % 3 == 0);
    for(int i = f; i < n; i += 3)
    {
        for(int j = 0; j < m; ++j)
        {
            a[i][j] = 'X';
        }
    }
    for(int i = f+1; i < n-1; i += 3)
    {
        int p = -1;
        for(int j = 0; j < m; ++j)
        {
            if(a[i+1][j] == 'X') p = j;
        }
        if(p != -1) a[i][p] = 'X';
        else
        {
            p = 0;
            for(int j = 0; j < m; ++j)
            {
                if(a[i][j] == 'X') p = j;
            }
            a[i][p] = a[i+1][p] = 'X';
        }
    }

    for(int i = 0; i < n; ++i)
    {
        cout << a[i] << "\n";
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    #ifdef MULTIPLE_CASES
    int t;
    cin >> t;
    for(int i = 0; i < t; ++i)
    {
        solve(i);
    }
    #else
    solve();
    #endif
}