//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int H, W;
char grid[25][25];
string pat;
int grid2[25][25];
int ay, ax;
int by, bx;

void bfs()
{
    const int INF = 100000000;
    int dy[4] = {0, -1, 0, 1};
    int dx[4] = {-1, 0, 1, 0};

    typedef pair<int, int> P;

    queue<P> que;
    rep(i,H) rep(j,W) {
        grid2[i][j] = INF;
    }

    que.push(P(ay, ax));
    grid2[ay][ax] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        rep(i,4) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];

            if (0 <= ny && ny < H && 0 <= nx && nx < W && grid[ny][nx] == '.' && grid2[ny][nx] == INF) {
                que.push(P(ny, nx));
                grid2[ny][nx] = grid2[p.first][p.second] + 1;
            }
        }
    }
}

int main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;

        rep(i,H) rep(j,W) {
            cin >> grid[i][j];
            if (grid[i][j] == 'A') {
                ay = i;
                ax = j;
                grid[i][j] = '.';
            } else if (grid[i][j] == 'B') {
                by = i;
                bx = j;
                grid[i][j] = '.';
            }
        }
        cin >> pat;

        /*
        int sy = 0, sx = 0;
        rep(i,pat.length()) {
            if (pat[i] == '5') {
                sy += 0;
                sx += 0;
            } else if(pat[i] == '4') {
                sy += 0;
                sx -= 1;
            } else if (pat[i] == '8') {
                sy -= 1;
                sx += 0;
            } else if (pat[i] == '6') {
                sy += 0;
                sx += 1;
            } else if (pat[i] == '2') {
                sy += 1;
                sx += 0;
            }
        }
        bool try_only_one = false;
        if (sy == 0 && sx == 0) try_only_one = true;
        */

        bfs();

        /*
        rep(i,H) {
            rep(j,W) {
                printf("% 3d ", grid2[i][j]);
            }
            cout << endl;
        }
        */

        bool possible = false;
        int ans;
        int ansy, ansx;
        int cnt = 0;
        rep(i,100) {
            rep(j,pat.length()) {
                cnt++;
                if (pat[j] == '5') {
                    by += 0;
                    bx += 0;
                } else if(pat[j] == '4') {
                    by += 0;
                    if (bx >= 1) bx -= 1;
                } else if (pat[j] == '8') {
                    if (by >= 1) by -= 1;
                    bx += 0;
                } else if (pat[j] == '6') {
                    by += 0;
                    if (bx < W - 1) bx += 1;
                } else if (pat[j] == '2') {
                    if (by < H - 1) by += 1;
                    bx += 0;
                }
                if (grid2[by][bx] <= cnt && !possible) {
                    possible = true;
                    ans = cnt;
                    ansy = by;
                    ansx = bx;
                }
            }
        }

        if (possible) {
            cout << ans << " " << ansy << " " << ansx << endl;
        } else {
            cout << "impossible" << endl;
        }
    }
}

Measured memory_bytes: 3192