#pragma region
//#pragma optimize("Ofast")
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, a, n) for (int i = n; i >= a; --i)
#pragma endregion
const int maxn = 505;
char s[maxn][maxn];
int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        int n, m;
        scanf("%d%d", &n, &m);
        rep(i, 1, n) scanf("%s", s[i] + 1);
        int l = (m % 3 ? 1 : 2), r = (m % 3 == 1 ? m : m - 1);
        rep(i, 1, n) s[i][r] = 'X';
        for (int j = l; j < r; j += 3) {
            int x = 1;
            rep(i, 1, n) {
                s[i][j] = 'X';
                if (s[i][j + 1] == 'X' || s[i][j + 2] == 'X') x = i;
            }
            s[x][j + 1] = s[x][j + 2] = 'X';
        }
        rep(i, 1, n) puts(s[i] + 1);
    }
}
