#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef pair <int, int> PII;
typedef pair <PII, PII> PPP;
typedef pair <int, PPP> NODE;
typedef priority_queue <NODE, vector<NODE>, greater<NODE> > QUEUE;
typedef vector <string> VS;

bool V[21][21][21][21][11];

void solve( int w, int h ) {
    VS M(h);
    for ( int i = 0; i < h; ++ i ) {
        cin >> M[i];
    }
    int sr, sc, gr, gc;
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            if ( M[i][j] == 'A' ) {
                sr = i;
                sc = j;
            }
            if ( M[i][j] == 'B' ) {
                gr = i;
                gc = j;
            }
        }
    }
    string s;
    cin >> s;
    int n = s.size();
    QUEUE Q;
    NODE start( 0, PPP( PII( sr, sc ), PII( gr, gc ) ) );
    Q.push( start );
    for ( int i = 0; i < 21; ++ i ) {
        for ( int j = 0; j < 21; ++ j ) {
            for ( int k = 0; k < 21; ++ k ) {
                for ( int l = 0; l < 21; ++ l ) {
                    for ( int m = 0; m < 11; ++ m ) {
                        V[i][j][k][l][m] = false;
                    }
                }
            }
        }
    }

    while ( ! Q.empty() ) {
        NODE node = Q.top();
        Q.pop();

        int cost = node.first;
        int r1 = node.second.first.first;
        int c1 = node.second.first.second;
        int r2 = node.second.second.first;
        int c2 = node.second.second.second;
        if ( r1 == r2 && c1 == c2 ) {
            cout << cost << " " << r1 << " " << c1 << endl;
            return;
        }
        
        int ncost = cost + 1;
        int nr2 = r2;
        int nc2 = c2;
        if ( s[cost%n] == '8' ) {
            nr2 --;
        } else if ( s[cost%n] == '2' ) {
            nr2 ++;
        } else if ( s[cost%n] == '6' ) {
            nc2 ++;
        } else if ( s[cost%n] == '4' ) {
            nc2 --;
        }
        if ( nr2 < 0 || nr2 >= h ) nr2 = r2, nc2 = c2;
        if ( nc2 < 0 || nc2 >= w ) nr2 = r2, nc2 = c2;

        const int dr[5] = { 0, 0, 1, -1, 0 };
        const int dc[5] = { 1, -1, 0, 0, 0 };
        for ( int k = 0; k < 5; ++ k ) {
            int nr1 = r1 + dr[k];
            int nc1 = c1 + dc[k];
            if ( nr1 < 0 || nr1 >= h ) nr1 = r1, nc1 = c1;
            if ( nc1 < 0 || nc1 >= w ) nr1 = r1, nc1 = c1;
            if ( M[nr1][nc1] == '#' ) continue;
            if ( V[nr1][nc1][nr2][nc2][ncost%n] ) continue;
            V[nr1][nc1][nr2][nc2][ncost%n] = true;
            NODE next_node( ncost, PPP( PII( nr1, nc1 ), PII( nr2, nc2 ) ) );
            Q.push( next_node );
        }
    }

    cout << "impossible" << endl;
}

int main() {
    int h, w;
    while ( cin >> h >> w && h && w ) {
        solve( w, h );
    }
    return 0;
}