#include <stdio.h>
#include <string.h>

#define N	500
#define M	500

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		static char cc[N][M + 1];
		int n, m, i, j;

		scanf("%d%d", &n, &m);
		for (i = 0; i < n; i++)
			scanf("%s", cc[i]);
		for (i = n % 3 == 0 ? 1 : 0; i < n; i += 3) {
			memset(cc[i], 'X', m * sizeof *cc[i]);
			if (i >= 3) {
				j = m == 1 || cc[i - 1][1] == '.' && cc[i - 2][1] == '.' ? 0 : 1;
				cc[i - 1][j] = cc[i - 2][j] = 'X';
			}
		}
		for (i = 0; i < n; i++)
			printf("%s\n", cc[i]);
	}
	return 0;
}
