#include<queue>
#include<string>
#include<iostream>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;

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

int main(){
	for(int w,h;cin>>h>>w,h;){
		char grid[20][21];
		int px,py,qx,qy;
		for(int i=0;i<h;i++){
			cin>>grid[i];
			for(int j=0;j<w;j++){
				if(grid[i][j]=='A')	px=j,py=i,grid[i][j]='.';
				if(grid[i][j]=='B')	qx=j,qy=i,grid[i][j]='.';
			}
		}
		string cmd;	cin>>cmd;

		int girlcost[20][20];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	girlcost[i][j]=1<<30;
		girlcost[py][px]=0;
		queue< pair<int,pii> > qu;	qu.push(mp(0,mp(px,py)));
		while(!qu.empty()){
			pair<int,pii> a=qu.front();	qu.pop();
			int cost=a.first,x=a.second.first,y=a.second.second;
			for(int i=0;i<4;i++){
				int xx=x+dx[i],yy=y+dy[i];
				if(0<=xx && xx<w && 0<=yy && yy<h && grid[yy][xx]!='#'){
					int nextcost=cost+1;
					if(nextcost<girlcost[yy][xx]){
						qu.push(mp(nextcost,mp(xx,yy)));
						girlcost[yy][xx]=nextcost;
					}
				}
			}
		}

		int ans=1<<30,ansx,ansy;
		int len=cmd.length();
		bool visited[20][20][10]={};
		for(int t=0,i=0;;t++,i=(i+1)%len){
			if(t>w*h && visited[qy][qx][i])	break;
			visited[qy][qx][i]=true;

			if(girlcost[qy][qx]<=t){
				ans=t;
				ansx=qx;
				ansy=qy;
				break;
			}

			switch(cmd[i]){
				case '2':	if(qy<h-1)	qy++; break;
				case '4':	if(qx>0)	qx--; break;
				case '6':	if(qx<w-1)	qx++; break;
				case '8':	if(qy>0)	qy--; break;
			}
		}

		if(ans<(1<<30))	cout<<ans<<' '<<ansy<<' '<<ansx<<endl;
		else			cout<<"impossible"<<endl;
	}

	return 0;
}