#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define maxN 505
#define mod 1000000007
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
int n,m;
char mp[maxN][maxN];
int main()
{
    int T;cin>>T;
    while(T--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;++i) cin>>mp[i]+1;
        if(n%3==0||n%3==2){
            for(int i=2;i<=n;i+=3){
                for(int j=1;j<=m;++j) mp[i][j]='X';
                if(i>2){
                    bool f=true;
                    for(int j=1;j<=m;++j){
                        if(mp[i-1][j]=='X'||mp[i-2][j]=='X'){
                            mp[i-1][j]='X';mp[i-2][j]='X';
                            f=false;
                            break;
                        }
                    }
                    if(f) mp[i-1][m]=mp[i-2][m]='X';
                }
            }
        }
        else{
            for(int i=1;i<=n;i+=3){
                for(int j=1;j<=m;++j) mp[i][j]='X';
                if(i>2){
                    bool f=true;
                    for(int j=1;j<=m;++j){
                        if(mp[i-1][j]=='X'||mp[i-2][j]=='X'){
                            mp[i-1][j]='X';mp[i-2][j]='X';
                            f=false;
                            break;
                        }
                    }
                    if(f) mp[i-1][m]=mp[i-2][m]='X';
                }
            }
        }
        for(int i=1;i<=n;++i) cout<<mp[i]+1<<"\n";
    }
}