#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define V vector<ll>
#define VV vector<vector<ll>>
#define A(a) for(auto &x:a)cin>>x;
#define C(a) cout<<(#a);for(auto x:a)cout<<" "<<x;cout<<endl;
#define D(a) cout<<(#a)<<"-> "<<a<<endl;
#define DD(a,b) cout<<(#a)<<"-> "<<a<<" "<<(#b)<<"-> "<<b<<endl;
#define F(n) for(int i=0;i<n;i++)
#define Q int tt,qq; cin>>tt ;for(qq=1;qq<=tt;qq++)
#define I ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define B(a) a.begin(),a.end()
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
ll M=1000000007,inf=92233720368547;
#define N 200010
int main()
{
	Q
	{
		ll n,m,i,j,t;
		cin>>n>>m;
		string s[n+1];
		for(i=0;i<n;i++)cin>>s[i];
		for(i=0;i<m;i++)s[n]+='.';
		if(n%3==1){t=0;}
		else t=1;
		for(i=t;i<n;i+=3){
			for(j=0;j<m;j++)s[i][j]='X';
		}
		for(i=t+1;i<n-t;i+=3){
			for(j=0;j<m;j++){
				if(s[i][j]=='X'||s[i+1][j]=='X')break;
			}
			// DD(i,j)
			if(j==m){
				s[i][0]='X';
				s[i+1][0]='X';
			}
			else{
				s[i][j]='X';
				s[i+1][j]='X';
			}
		}
		for(i=0;i<n;i++)cout<<s[i]<<endl;
	}
}