#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>

#define pb push_back
#define mp make_pair
#define contains(c, x) (c).find(x) != (c).end()
#define rep(i, n) for(int i = 0; i < n; ++i)

using namespace std;

int h, w;
vector<string> grid(21);
string pattern;
int g[21][21];

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

int p2i(int Time)
{
	switch (pattern[Time % pattern.size()] - '0') {
		case 5: return 0;
		case 8: return 2;
		case 6: return 4;
		case 4: return 1;
		case 2: return 3;
	}
}

int main()
{
	while (true) {
		cin >> h >> w; if (h == 0 && w == 0) break;
		rep(i, h) cin >> grid[i];
		cin >> pattern;
		
		pair<int, int> a, b;
		rep(i, h) rep(j, w)
			if (grid[i][j] == 'A') a = mp(i, j);
			else if (grid[i][j] == 'B') b = mp(i, j);

		rep(i, h) rep(j, w) g[i][j] = -1;
		queue<pair<int, int> > q;
		map<pair<int, int>, int> m;
		q.push(a);
		m[a] = 0;
		while (!q.empty()) {
			pair<int, int> t = q.front(); q.pop();
			g[t.first][t.second] = m[t];
			rep(i, 5) {
				int dr = t.first + dy[i];
				int dc = t.second + dx[i];
				pair<int, int> next = mp(dr, dc);
				if (dr < 0 || dr >= h || dc < 0 || dc >= w) continue;
				if (grid[dr][dc] == '#' || contains(m, next)) continue;
				q.push(next);
				m[next] = m[t] + 1;
			}
		}
		int T = 1;
		while (T < 10000) {
			rep(i, pattern.size()) {
				int k = p2i(T-1);
				int br = b.first + dy[k];
				int bc = b.second + dx[k];
				if (0 <= br && br < h && 0 <= bc && bc < w)
					b = mp(b.first + dy[k], b.second + dx[k]);
				br = b.first;
				bc = b.second;
				if (g[br][bc] >= 0 && g[br][bc] <= T) {
					cout << max(g[br][bc], T) << " " << br << " " << bc << endl;
					goto CONTINUE;
				}
				T++;
			}
		}
		cout << "impossible" << endl;
CONTINUE:;
	}
	return 0;
}