#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#define ios             ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define bug(str, x)     cerr << "# " << str << " : " << x << '\n'
#define here(x)         cerr << "here " << x << '\n'

using namespace std;
typedef long long ll;
const int maxn = 5e2 + 10;
const int inf = 1e9;
char grid[maxn][maxn];

int main(){
	ios;
	int t;
	cin >> t;
	while(t--){
		int n, m;
		cin >> n >> m;
		for(int i = 0; i < n; i ++){
			for(int j = 0; j < m; j ++){
				cin >> grid[i][j];
			}
		}
		for(int c = (m % 3 != 1 ? 1 : 0); c < m; c += 3){
			for(int r = 0; r < n; r ++){
				grid[r][c] = 'X';
			}
		}
		for(int c = (m % 3 != 1 ? 2 : 1); c < m - 1; c += 3){
			bool fg = true;
			for(int r = 0; r < n; r ++){
				if(grid[r][c] == 'X'){
					grid[r][c + 1] = 'X';
					fg = false;
					break;
				}
				if(grid[r][c + 1] == 'X'){
					grid[r][c] = 'X';
					fg = false;
					break;
				}
			}
			if(fg){
				grid[0][c] = grid[0][c + 1] = 'X';
			}
		}
		for(int i = 0; i < n; i ++){
			for(int j = 0; j < m; j ++){
				cout << grid[i][j];
			}
			cout << '\n';
		}
		cout << '\n';
	}
}

