#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#define all(c) c.begin(),c.end()
#define pb push_back
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
int w,h;
vector<string> s;
P d[10];
int antime;
P q;
map<int,int> mp;
string op;
int dp[20][20];
bool in(P n){
	if(n.second>=0&&n.second<w&&n.first>=0&&n.first<h)
		return true;
	return false;
}
int ans;
int ret(P b,int time){
	//cout<<b.first<<"  "<<b.second<<endl;
	if(time>400)
	return INF;
	if(dp[b.first][b.second]<=time){
		q.first=b.first;
		q.second=b.second;
		return time;
	}
	P nb;
	nb.first=b.first+d[op[time%op.size()]-'0'].first;
	nb.second=b.second+d[op[time%op.size()]-'0'].second;
	if(!in(nb))
		nb=b;
	return ret(nb,time+1);
}
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void bfs(P a){
	queue<P> que;
	que.push(a);
	dp[a.first][a.second]=0;
	while(!que.empty()){
		P t=que.front(),nt;
		que.pop();
		//cout<<dp[t.first][t.second]<<endl;
		for(int i=0;i<4;i++){
			nt.first=t.first+dy[i];
			nt.second=t.second+dx[i];
			if(in(nt)&&dp[nt.first][nt.second]==INF&&s[nt.first][nt.second]!='#'){
				que.push(nt);
				dp[nt.first][nt.second]=dp[t.first][t.second]+1;
			}
		}
	}
}
int main(){
	d[5]=P(0,0);d[8]=P(-1,0);d[6]=P(0,1);d[4]=P(0,-1);d[2]=P(1,0);
	mp[0]=5;mp[1]=8;mp[2]=6;mp[3]=4;mp[4]=2;
	while(cin>>h>>w,h||w){
		s.clear();
		P a,b;
		antime=INF;
		//memset(dp,-1,sizeof(dp));
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		dp[i][j]=INF;
		for(int i=0;i<h;i++){
			string t;
			cin>>t;
			s.pb(t);
			for(int j=0;j<t.size();j++){
				if(t[j]=='A'){
					a.first=i;a.second=j;
				}else if(t[j]=='B'){
					b.first=i;b.second=j;
				}
			}
		}
		cin>>op;
		bfs(a);
		int ans=ret(b,0);
		if(ans!=INF)
			cout<<ans<<" "<<q.first<<" "<<q.second<<endl;
		else
			cout<<"impossible"<<endl;
	}
	return 0;
}