#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

const int INF = 1e+8;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef pair<PP,int> State;

// 入力
int w, h;
string s[20], p;

// d[ay][ax][by][bx][i] := (ax,ay),(bx,by),i分目のときの手数
// 5次元配列とかやばすぎ.
int d[20][20][20][20][10];

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

void debug(int ax, int ay, int bx, int by, int t){
	cout << "[debug]" << " t:" << t << endl;
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( x == ax && y == ay ){
				cout << "A";
			}else if( x == bx && y == by ){
				cout << "B";
			}else{
				cout << s[y][x];
			}
		}
		cout << endl;
	}
	cout << endl;
}

// 初期化 
void ini(){
	for(int ay=0 ; ay < h ; ay++ ){
		for(int ax=0 ; ax < w ; ax++ ){
			for(int by=0 ; by < h ; by++ ){
				for(int bx=0 ; bx < w ; bx++ ){
					for(int i=0 ; i < p.size() ; i++ ){
						d[ay][ax][by][bx][i] = INF;
					}
				}
			}
		}
	}
}

// 幅優先探索.
pair<int,P> bfs(int ax, int ay, int bx, int by){
	queue<State> q;
	PP pp(P(ax,ay),P(bx,by));
	q.push( State( pp , 0 ) );
	d[ay][ax][by][bx][0] = 0;
	ini();
	
	while( !q.empty() ){
		int ax = q.front().first.first.first;
		int ay = q.front().first.first.second;
		int bx = q.front().first.second.first;
		int by = q.front().first.second.second;
		int t  = q.front().second;
		q.pop();
		//debug(ax,ay,bx,by,t);
		
		int bx_ = bx + dx[p[t % p.size()]];
		int by_ = by + dy[p[t % p.size()]];
		if( bx_ < 0 || w <= bx_ ) bx_ = bx;
		if( by_ < 0 || h <= by_ ) by_ = by;
		P b(bx_,by_);
		for(int i=0 ; i < 4 ; i++ ){
			int ax_ = ax + dx[i];
			int ay_ = ay + dy[i];
			if( ax_ < 0 || w <= ax_ ) ax_ = ax;
			if( ay_ < 0 || h <= ay_ ) ay_ = ay;
			if( s[ay_][ax_] == '#' ){
				ax_ = ax; ay_ = ay;
			}
			P a(ax_,ay_);
			
			if( a == b ){ // ゴールの時
				return pair<int,P>(t+1,a);
			}else if( d[ay_][ax_][by_][bx_][(t+1) % p.size()] == INF ){
				d[ay_][ax_][by_][bx_][(t+1) % p.size()] = t+1;
				PP pp(P(ax_,ay_),P(bx_,by_));
				q.push( State( pp , t+1 ) );
			}
		}
	}
	return pair<int,P>(-1,P(0,0));
}

int main(){
	dx['6'] = 1; dx['4'] = -1; dy['8'] = -1; dy['2'] = 1;
	
	while( cin >> h >> w , h || w ){
		for(int y=0 ; y < h ; y++ ){
			cin >> s[y];
		}
		cin >> p;
		
		int ax, ay, bx, by;
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				if( s[y][x] == 'A' ){
					ax = x; ay = y; s[y][x] = '.';
				}
				if( s[y][x] == 'B' ){
					bx = x; by = y; s[y][x] = '.';
				}
			}
		}
		
		pair<int,P> ans = bfs(ax, ay, bx, by);
		if( ans.first == -1 ){
			cout << "impossible" << endl;
		}else{
			cout << ans.first << " ";
			cout << ans.second.second << " ";
			cout << ans.second.first << endl;
		}
	}
}