#include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;

int x[4]={-1,0,0,1},y[4]={0,-1,1,0};
int main(){
    int a,b;
    string s[20];
    while(cin>>a>>b,a|b){
	P n,m;
	for(int c=0;c<a;c++){cin>>s[c];
	    for(int i=0;i<b;i++){
		if(s[c][i]=='A'){n=P(c,i);s[c][i]='.';}
		else if(s[c][i]=='B'){m=P(c,i);s[c][i]='.';}
		}
	    }
	string d;cin>>d;
	int mincost[20][20];
	memset(mincost,-1,sizeof(mincost));
	queue<P>Q;
	Q.push(n);
	mincost[n.first][n.second]=0;
	while(Q.size()){
	    P t=Q.front();Q.pop();
	    for(int i=0;i<4;i++){
		int dx=t.first+x[i],dy=t.second+y[i];
		if(dx>=0&&dx<a&&dy>=0&&dy<b&&mincost[dx][dy]==-1&&s[dx][dy]=='.'){
		    mincost[dx][dy]=mincost[t.first][t.second]+1;
		    Q.push(P(dx,dy));
		    }
		}
	    }
	    int X=m.first,Y=m.second;
	for(int i=0;i<1000;i++){
            if(mincost[X][Y]!=-1&&mincost[X][Y]<=i){cout<<i<<" "<<X<<" "<<Y<<endl;goto r;}
	    switch(d[i%d.length()]){
		case '2':X++;break;
		case '6':Y++;break;
		case '4':Y--;break;
		case '8':X--;break;
	    }
	    if(X==a)X=a-1;
	    if(X==-1)X=0;
	    if(Y==b)Y=b-1;
	    if(Y==-1)Y=0;
	     }
	     puts("impossible");
	     r:;
	    }
    }