#include<iostream>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pi;
#define MAX 32
#define fr first
#define sc second

const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};
static const int di_sz = sizeof(di)/sizeof(*di);

inline pi comp(pi p, int H, int W){
  if(p.fr>=H)p.fr=H-1;
  if(p.fr<0)p.fr=0;
  if(p.sc>=W)p.sc=W-1;
  if(p.sc<0)p.sc=0;
  return p;
}

struct ghost{
  pi p;
  ghost():p(0,0){}
  ghost(pi p):p(p){}
  void move(int ind, const string &pat, int H, int W){
    pi next=p;
    switch(pat[ind]){
    case '5':return;break;
    case '8':next.fr--;break;
    case '6':next.sc++;break;
    case '4':next.sc--;break;
    case '2':next.fr++;break;
    }
    if(next.fr>=H)next.fr=H-1;
    if(next.fr<0)next.fr=0;
    if(next.sc>=W)next.sc=W-1;
    if(next.sc<0)next.sc=0;
    p = next;
  }
};

struct state{
  int now;
  pi girl;
  vector<ghost> g;
  bool operator<(const state &t)const{
    if(now!=t.now)return now<t.now;
    if(girl.fr!=t.girl.fr)return girl.fr<t.girl.fr;
    if(girl.sc!=t.girl.sc)return girl.sc<t.girl.sc;
    for(int i=0;i<g.size();++i){
      if(g[i].p.fr!=t.g[i].p.fr)return g[i].p.fr<t.g[i].p.fr;
      if(g[i].p.sc!=t.g[i].p.sc)return g[i].p.sc<t.g[i].p.sc;
    }
    return false;
  }
};

int bfs(state init, int H, int W, char M[][MAX], const string &pat, pi &ans_pos){
  map<state,int> vis;
  queue<state> qs;
  vis[init]=0;
  qs.push(init);

  while(!qs.empty()){
    state nst = qs.front(); qs.pop();
    int ns = vis[nst];

    for(int i = 0; i < nst.g.size(); ++i){
      if( nst.girl.fr == nst.g[i].p.fr && nst.girl.sc == nst.g[i].p.sc ){
	ans_pos = nst.girl;
	return ns;
      }
    }

    for(int k = 0; k < di_sz; ++k){
      state Next=nst;
      pi next(nst.girl.fr+di[k], nst.girl.sc+dj[k]);
      next =comp(next,H,W);
      if(M[next.fr][next.sc]=='#')next=nst.girl;
      Next.girl = next;
    
      // move ghosts;
      for(int i = 0; i < nst.g.size(); ++i){
	Next.g[i].move( nst.now, pat, H, W );
      }
      Next.now++;
      if(Next.now>=pat.length()){
	Next.now=0;
      }
      
      if( vis.find(Next) == vis.end() ){
	vis[Next]=ns+1;
	qs.push(Next);
      }else if( vis[Next] > ns+1 ){
	vis[Next]=ns+1;
	qs.push(Next);
      }
    }

  }
  return -1;
}


int main()
{
  while(true){
    int H,W;
    string pat;
    state init;
    char M[MAX][MAX] = {{0,},};
    cin >> H >> W;
    if( H == 0 && W == 0 )break;
    
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	char c; cin >> c;
	if( c == 'A'){
	  init.girl = make_pair(i,j);
	  M[i][j]='.';
	}else if( c == 'B'){
	  init.g.push_back( ghost(make_pair(i,j) ) );
	  M[i][j]='.';
	}else{
	  M[i][j]=c;
	}
      }
    }
    init.now=0;
    cin >> pat;
    pi ans_pos;
    int ans_step = bfs(init,H,W,M,pat,ans_pos);
    if( ans_step >= 0 ){
      cout << ans_step << ' ' << ans_pos.fr << ' ' << ans_pos.sc << endl;
    }else{
      cout << "impossible" << endl;
    }
  }
  return 0;
}