#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 505;
char c[N][N];
int main() {
	int T; scanf("%d", &T);
	while (T--) {
		int n, m;
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)
			scanf("%s", c[i] + 1);
		if (n <= 2) {
			for (int j = 1; j <= m; j++) c[1][j] = 'X';
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++)
					putchar(c[i][j]);
				putchar('\n');
			}
			continue;
		}
		for (int i = 3; i <= n; i += 3) {
			for (int j = 1; j <= m; j++) c[i][j] = 'X';
			if (i == 3) {
				for (int j = 1; j <= m; j++)
				if (c[i - 2][j] == 'X' || c[i - 1][j] == 'X')
				c[i - 2][j] = c[i - 1][j] = 'X';
				continue;
			}
			int flag = 1;
			for (int j = 1; j <= m; j++)
				if (c[i - 2][j] == 'X' || c[i - 1][j] == 'X') {
					flag = j;
					break;
				}
			c[i - 2][flag] = c[i - 1][flag] = 'X';
		}
		if (n % 3 == 2) {
			for (int j = 1; j <= m; j++)
			if (c[n - 1][j] == 'X' || c[n][j] == 'X')
				c[n - 1][j] = c[n][j] = 'X';
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++)
				putchar(c[i][j]);
			putchar('\n');
		}
	}
	return 0;
}