#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> Pi;
typedef pair<P,Pi> Pii;
int H,W;
char mas[22][22];
string pat;
int ax,ay,bx,by;
int dx[] = {0,1,-1,0,0};
int dy[] = {0,0,0,-1,1};

int solved(){
  bool used[10][20][20][20][20];
  memset(used,false,sizeof(used));
  queue<Pii> que;
  int len = pat.size();
  que.push(Pii(P(0,0),Pi(P(ax,ay),P(bx,by))));
  used[0][ax][ay][bx][by] = true;
  while(!que.empty()){
    Pii p = que.front(); que.pop();
    int cnt = p.first.first;
    int idx = p.first.second;
    int Ax = p.second.first.first;
    int Ay = p.second.first.second;
    int Bx = p.second.second.first;
    int By = p.second.second.second;
    if(Ax == Bx && Ay == By) {
      cout << cnt << " " << Ay << " " << Ax << endl;
      return 1;
    }
    int nBx = Bx;
    int nBy = By;
    if(pat[idx] == '8') nBy = max(0,nBy-1);
    else if(pat[idx] == '6') nBx = min(W-1,nBx+1);
    else if(pat[idx] == '4') nBx = max(0,nBx-1);
    else if(pat[idx] == '2') nBy = min(H-1,nBy+1);
    for(int i=0;i<5;i++){
      int nAx = Ax+dx[i];
      int nAy = Ay+dy[i];
      if(nAx >= W || nAx < 0) nAx = Ax;
      if(nAy >= H || nAy < 0) nAy = Ay;
      if(mas[nAy][nAx] != '#'){
	int next = (idx+1)%len;
	if(used[next][nAx][nAy][nBx][nBy] == false){
	  used[next][nAx][nAy][nBx][nBy] = true;
	  que.push(Pii(P(cnt+1,next),Pi(P(nAx,nAy),P(nBx,nBy))));
	}	
      }
    }
  }
  return 0;
}

int main(){
  while(1){
    cin >> H >> W;
    if(H == 0 && W == 0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> mas[i][j];
	if(mas[i][j] == 'A'){
	  ax = j;
	  ay = i;
	}
	if(mas[i][j] == 'B'){
	  bx = j;
	  by = i;
	}
      }
    }
    cin >> pat;
    if(solved() == 0){
      cout << "impossible" << endl;
    }
  }
}