#include <iostream>
#include <string>
#include <queue>
#include <tuple>
#include <cstdio>
using namespace std;
typedef tuple<int, int, int> T;

int h, w;
string s[20];
int meY, meX;
int gostY, gostX;
string moves;

int minCost[20][20];
int INF = 1000;

int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

void outAns() {
	int y = gostY;
	int x = gostX;
	
	for (int i = 0; i < INF; i++) {
		if (minCost[y][x] <= i) {
			cout << i << " " << y << " " << x << endl;
			return;
		}
		
		char type = moves[i % moves.length()];
		string dir = "8624";
		int j;
		for (j = 0; j < 4; j++) {
			if (dir[j] == type) {
				break;
			}
		}
		if (j == 4) continue;
		
		//?????? == j??§?§????
		int ny = y + dy[j];
		int nx = x + dx[j];
		if (0 <= ny && ny < h && 0 <= nx && nx < w) {
			y = ny;
			x = nx;
		}
	}
	cout << "impossible" << endl;
}

int main() {
	while (cin >> h >> w, h) {
		int i, j;
		for (i = 0; i < h; i++) cin >> s[i];
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				if (s[i][j] == 'A') {
					meY = i;
					meX = j;
				}
				if (s[i][j] == 'B') {
					gostY = i;
					gostX = j;
				}
			}
		}
		cin >> moves;
		
		for (i = 0; i < h; i++) for (j = 0; j < w; j++) minCost[i][j] = INF;
		
		queue<T> que;	//cst, y, x
		que.push(T(0, meY, meX));
		while (!que.empty()) {
			T now = que.front(); que.pop();
			int cst = get<0>(now);
			int y = get<1>(now);
			int x = get<2>(now);
			if (minCost[y][x] <= cst) continue;
			minCost[y][x] = cst;
			
			for (int i = 0; i < 4; i++) {
				int ny = y + dy[i];
				int nx = x + dx[i];
				if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
				if (s[ny][nx] == '#') continue;
				que.push(T(cst + 1, ny, nx));
			}
		}
		
		outAns();
	}
	return 0;
}