#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
//int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem1046 : Ghost Buster! **/
int dx[]={-1, 0, 1, 0, 0}, dy[]={0, -1, 0, 1, 0};

int W, H;
string s;

struct P {
	int x, y;
	P(){}
	P(int _x, int _y) : x(_x), y(_y) {}
};

struct S {
	P p;
	int time;
	S(){}
	S(P _p, int _time) : p(_p), time(_time) {}
};

typedef pair<S, S> SS;

int main()
{
	
	while (cin>>H>>W, W||H) {
		char field[20][20];
		
		S A, B;
		
		rep(i, H) rep(j, W) {
			cin>>field[i][j];
			if (field[i][j] == 'A')
				A = S(P(j, i), 0);
			else if (field[i][j] == 'B')
				B = S(P(j, i), 0);
		}
		cin>>s;
		int N = (int)s.size();
		
		queue<SS> Q;
		bool vis[H][W][H][W][10];
		memset(vis, 0, sizeof(vis));
		
		Q.push(SS(A, B));
		vis[A.p.y][A.p.x][B.p.y][B.p.x][0] = true;
		
		while (Q.size()) {
			SS ss = Q.front(); Q.pop();
			S a = ss.first, b = ss.second;

			//cerr << "(" << a.p.x << ", " << a.p.y << ")" << " ";
			//cerr << "(" << b.p.x << ", " << b.p.y << ")" << " " << a.time << endl;
			
			if (a.p.x == b.p.x && a.p.y == b.p.y) {
				cout << a.time << " " << a.p.y << " " << a.p.x << endl;
				goto end;
			}
						
			// Move Ghost
			if (s[b.time%N] == '8' && b.p.y>0)
				b.p.y--;
			else if (s[b.time%N] == '6' && b.p.x<W-1)
				b.p.x++;
			else if (s[b.time%N] == '4' && b.p.x>0)
				b.p.x--;
			else if (s[b.time%N] == '2' && b.p.y<H-1)
				b.p.y++;
			b.time++;
			
			// Move Girl
			a.time++;
			rep(i, 5) {
				int nx = a.p.x + dx[i], ny = a.p.y + dy[i];
				if_range(nx, ny, W, H) {
					if (!vis[ny][nx][b.p.y][b.p.x][a.time%N] && field[ny][nx] != '#') {
						Q.push(SS(S(P(nx, ny), a.time), b));
						vis[ny][nx][b.p.y][b.p.x][a.time%N] = true;
					}
				}
			}
			
			if (!vis[a.p.y][a.p.x][b.p.y][b.p.x][b.time%N]) {
				Q.push(SS(a, b));
				vis[a.p.y][a.p.x][b.p.y][b.p.x][b.time%N] = true;
			}
		}
		cout << "impossible" << endl;
	end:;
	}
}