import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    alias Tuple!(int, "x", int, "y") P;
    const id = [
        '5': P(0, 0), 
        '8': P(0, -1),
        '6': P(1, 0),
        '4': P(-1, 0),
        '2': P(0, 1),
    ];
    const dy = [1, 0, -1, 0],
          dx = [0, 1, 0, -1];

    int H, W;
    string[] F;
    string Pat;
    bool input() {
        scanf("%d %d\n", &H, &W);
        if (H == 0 && W == 0) return false;
        F = new string[H];
        foreach (i; 0 .. H) {
            F[i] = readln.chomp;
        }
        Pat = readln.chomp;
        return true;
    }

    void solve() {
        int[][] X = new int[][](H, W);
        foreach (i; 0 .. H) X[i][] = int.max;
        
        P find(char c) {
            foreach (i; 0 .. H)
                foreach (j; 0 .. W) 
                    if (F[i][j] == c) return P(j, i);
            assert(false);
        }

        P s = find('A');
        struct S {
            P p;
            int t;
        }
        DList!S Q;
        Q.insert(S(s, 0));
        X[s.y][s.x] = 0;
        while (!Q.empty) {
            S c = Q.front; Q.removeFront;
            foreach (i; 0 .. 4) {
                int ny = c.p.y + dy[i],
                    nx = c.p.x + dx[i],
                    nt = c.t + 1;
                if (ny < 0 || ny >= H) continue;
                if (nx < 0 || nx >= W) continue;
                if (F[ny][nx] == '#') continue;
                if (X[ny][nx] <= nt) continue;
                X[ny][nx] = nt;
                Q.insert(S( P(nx, ny), nt ));
            }
        }

        P g = find('B');
        int t = 0;
        while (true) {
            foreach (c; Pat) {
                t++;
                if (t > H * W * Pat.length) {
                    writeln("impossible");
                    return;
                }
                P d = id[c];
                int ny = g.y + d.y,
                    nx = g.x + d.x;
                if (ny < 0 || ny >= H) ny = g.y;
                if (nx < 0 || nx >= W) nx = g.x;
                if (X[ny][nx] <= t) {
                    writefln("%d %d %d", t, ny, nx);
                    return;
                }
                g.y = ny;
                g.x = nx;
            }
        }
    }

    while (input()) solve();
}