#include <stdio.h>

char map[52][52];
int poss[2][52][52][4];
int R, C;
int t, d;
int tx, ty;

void scenario(void) {
	int i, j;
	scanf("%i %i\n", &R, &C);
	for(i = 1; i <= R; ++i) {
		for(j = 1; j <= C; ++j) {
			scanf("%c", &map[i][j]);
			if(map[i][j] == 'X') {
				tx = j;
				ty = i;
			}
		}
		scanf("\n");
	}
	for(i = 0; i <= R + 1; ++i)
		map[i][0] = map[i][C + 1] = '#';
	for(j = 1; j <= C; ++j)
		map[0][j] = map[R + 1][j] = '#';
	R += 2;
	C += 2;
	scanf("%i %i\n", &t, &d);
}

void solve(void) {
	int k, i, j, dir, diro;
	int dx[4] = {1, -1, 0, 0};
	int dy[4] = {0, 0, 1, -1};
	for(i = 0; i != R; ++i)
		for(j = 0; j != C; ++j)
			for(dir = 0; dir != 4; ++dir)
				poss[0][i][j][dir] = (map[i][j] == 'U');
	for(k = 1; k != t + d; ++k) {
		int old = ((k - 1) & 1), now = (k & 1);
		for(i = 0; i != R; ++i) {
			for(j = 0; j != C; ++j) {
				for(dir = 0; dir != 4; ++dir) {
			
					poss[now][i][j][dir] = 0;
					if(map[i][j] == '#' || map[i][j] == 'U')
						continue;

					for(diro = 0; diro != 4; ++diro) {
						if(dx[diro] == -dx[dir] && dy[diro] == -dy[dir])
							continue;
						poss[now][i][j][dir] |=
							poss[old][i - dy[dir]][j - dx[dir]][diro];
					}
				}
			}
		}
		if(k >= t) {
			if(poss[now][ty][tx][0] ||
				poss[now][ty][tx][1] ||
				poss[now][ty][tx][2] ||
				poss[now][ty][tx][3]) {
				
				printf("%i\n\n", k);
				return;
			}
		}
	}
	printf("Impossible\n\n");
}

int main(void) {
	int N, Ni;
	scanf("%i\n", &N);
	for(Ni = 1; Ni <= N; ++Ni) {
		
		printf("Scenario #%i:\n", Ni);
		scenario();
		solve();
	}

	return 0;
}
