#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
using namespace std;

int n, m, T;
char s[505][505];

template < typename T >
inline T read()
{
	 T x = 0, w = 1; char c = getchar();
	 while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	 while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	 return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	 freopen("cpp.in", "r", stdin);
#endif
	 T = read <int> ();
	 while(T--)
	 {
		  n = read <int> (), m = read <int> ();
		  for(int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
		  if(n % 3 != 0)
		  {
				for(int i = 1; i <= n; i += 3)
					 for(int j = 1; j <= m; j++) s[i][j] = 'X';
				for(int i = 1; i <= n; i += 3)
					 if(i + 2 <= n)
					 {
						  bool flag = 0;
						  for(int j = 1; j <= m; j++) flag |= s[i + 1][j] == 'X';
						  for(int j = 1; j <= m; j++) flag |= s[i + 2][j] == 'X';
						  if(!flag) s[i + 1][1] = s[i + 2][1] = 'X';
						  else
						  {
								for(int j = 1; j <= m; j++) if(s[i + 1][j] == 'X') { s[i + 1][j] = s[i + 2][j] = 'X'; flag = 0; break; }
								if(flag) for(int j = 1; j <= m; j++) if(s[i + 2][j] == 'X') { s[i + 2][j] = s[i + 1][j] = 'X'; break; }
						  }
					 }
		  }
		  else
		  {
				for(int i = 2; i <= n; i += 3)
					 for(int j = 1; j <= m; j++) s[i][j] = 'X';
				for(int i = 2; i <= n; i += 3)
					 if(i + 2 <= n)
					 {
						  bool flag = 0;
						  for(int j = 1; j <= m; j++) flag |= s[i + 1][j] == 'X';
						  for(int j = 1; j <= m; j++) flag |= s[i + 2][j] == 'X';
						  if(!flag) s[i + 1][1] = s[i + 2][1] = 'X';
						  else
						  {
								for(int j = 1; j <= m; j++) if(s[i + 1][j] == 'X') { s[i + 1][j] = s[i + 2][j] = 'X'; flag = 0; break; }
								if(flag) for(int j = 1; j <= m; j++) if(s[i + 2][j] == 'X') { s[i + 2][j] = s[i + 1][j] = 'X'; break; }
						  }
					 }				
		  }
		  for(int i = 1; i <= n; i++) cout<<(s[i] + 1)<<endl;
	 }
	 return 0; 
}
