#include <cstdio>

int tcase,n,m;
char MAP[510][510];

int main()
{
    scanf("%d",&tcase);
    while(tcase--)
    {
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++) scanf("%s",MAP[i]+1);
        for(int i=1;i<=n;i+=3)
        {
            for(int j=1;j<=m;j++) MAP[i][j] = 'X';
            if(i+2 >= n) continue;
            for(int j=1;j<=m;j++) if(MAP[i+1][j] == 'X') { MAP[i+2][j] = 'X'; goto GOON; }
            for(int j=1;j<=m;j++) if(MAP[i+2][j] == 'X') { MAP[i+1][j] = 'X'; goto GOON; }
            MAP[i+1][1] = MAP[i+2][1] = 'X';
            GOON: continue;
        }
        if(n%3 == 0) for(int j=1;j<=m;j++) if(MAP[n][j] == 'X') MAP[n-1][j] = 'X';
        for(int i=1;i<=n;i++) printf("%s\n",MAP[i]+1);
    }
    return 0;
}
