#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
// S N E W
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

int H, W;
char map[20][20];
P a, b;
int d[20][20];
std::string pattern;

void bfs(){
    REP(i, 20){
        REP(j, 20){
            d[i][j] = INF;
        }
    }

    std::queue<State> q;
    q.push(mp(0, a));
    d[a.second][a.first] = 0;

    while(!q.empty()){
        State s = q.front(); q.pop();
        int cost = s.first;
        P p = s.second;

        if(d[p.second][p.first] < cost){continue;}
        
        REP(i, 4){
            int nx = p.first + dx[i],
                ny = p.second + dy[i];
            if(0 <= nx && nx < W &&
               0 <= ny && ny < H &&
               d[ny][nx] > cost + 1 && map[ny][nx] == '.'){
                q.push(mp(cost+1, mp(nx, ny)));
                d[ny][nx] = cost + 1;
            }
        }
    }
}

State buster(){
    std::string table = "2864";
    int index = 0, t = 1;
    while(t <= 400){
        REP(i, 4){
            if(pattern[index] == table[i]){
                int nx = b.first + dx[i], ny = b.second + dy[i];
                if(0 <= nx && nx < W &&
                   0 <= ny && ny < H){
                    b = mp(nx, ny);
                }
                break;
            }
        }

        if(t >= d[b.second][b.first]){
            return mp(t, b);
        }

        index = (index + 1) % pattern.size();
        t++;
    }

    return mp(t, mp(-1, -1));
}

int main(){
    while(std::cin >> H >> W, H){
        REP(i, H){
            REP(j, W){
                std::cin >> map[i][j];
                if(map[i][j] == 'A'){
                    a = mp(j, i);
                    map[i][j] = '.';
                }else if(map[i][j] == 'B'){
                    b = mp(j, i);
                    map[i][j] = '.';
                }
            }
        }

        std::cin >> pattern;

        bfs();

        // REP(i, H){
        //     REP(j, W){
        //         printf("%d, ", d[i][j]);
        //     }
        //     puts("");
        // }

        State res = buster();
        if(res.first > 400){
            puts("impossible");
        }else{
            printf("%d %d %d\n", res.first, res.second.second, res.second.first);
        }
    }
}