#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vec vector
#define pii pair<int, int> 
using namespace std;
 
const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = (int) 1e9;
 
long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}
 
ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
struct pt {
  ll x,y;
};

ll dot(const pt& p1, const pt& p2) {
  return p1.x * p2.x + p1.y * p2.y;
}

ll cross(const pt& p1, const pt& p2) {
 return p1.x * p2.y - p1.y * p2.x;
}

bool cmp_angles(const pt& p1, const pt& p2, const pt& p3, const pt& p4) {
  pt po1 = {dot(p1, p2), abs(cross(p1, p2))};
  pt po2 = {dot(p3, p4), abs(cross(p3, p4))};
  return cross(po1, po2) >= 0;
}
bool top(const pair<int, int> & p) {
  return p.second > 0 || (p.second == 0 && p.first < 0);
}
int a[101][101];

void inv(const pii& p) {
  a[p.first - 1][p.second - 1] = 1- a[p.first - 1][p.second - 1];
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  cin >> q;
  while (q-- >0) {
    int n;
    cin >> n;
    int m;
    cin >> m;
    int t[n][m];
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      for (int j = 0; j < m; ++j) {
        t[i][j] = (s[j] == 'X');
      }
    }
    for (int i = 0; i < n; i += 3) {
      for (int j = 0; j < m; ++j) t[i][j] = 1;
    }
    for (int i = 0; i + 2 < n; i += 3) {
      bool good = false;
      for (int j = 0; j < m; ++j) {
        if (t[i + 1][j] | t[i + 2][j]) {
          if (t[i + 1][j]) {
            t[i + 2][j] = 1;
          } else {
            t[i + 1][j] = 1;
          }
          good = true;
          break;
        }
      }
      if (!good) {
        t[i + 1][0] = t[i + 2][0] = 1;
      }
    }
    if (n % 3) {
      // nop
    } else if (n > 1){
      for (int j = 0; j < m; ++j) {
        if (t[n - 1][j]) {
          t[n - 2][j] = 1;
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      string s = "";
      for (int j = 0; j < m; ++j) {
        s += t[i][j] ? "X" : ".";
      }
      cout << s << "\n";
    }
  }

  return 0;
}
