#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

long INF = 1000000;

int main() {

    int h, w;
    while(cin >> h >> w && (h || w)) {
        queue<int> x;
        queue<int> y;
        char town[h][w];
        long time[h][w];
        int gx, gy;
        string str;
        getline(cin, str);
        for(int i = 0; i < h; i++) {
            getline(cin, str);
            for(int j = 0; j < w; j++) {
                time[i][j] = INF;
                town[i][j] = str[j];
                if(str[j] == 'A') {
                    x.push(i);
                    y.push(j);
                    town[i][j] = '.';
                    time[i][j] = 0;
                }
                if(str[j] == 'B') {
                    gx = i;
                    gy = j;
                    town[i][j] = '.';
                }
            }
        }

        while(!x.empty()) {
            int i = x.front();
            int j = y.front();
            x.pop();
            y.pop();
            if ( i > 0 && town[i-1][j] != '#' && time[i-1][j] == INF ) {
                time[i-1][j] = time[i][j] + 1;
                x.push(i-1);
                y.push(j);
            }
            if ( j > 0 && town[i][j-1] != '#' && time[i][j-1] == INF ) {
                time[i][j-1] = time[i][j] + 1;
                x.push(i);
                y.push(j-1);
            }
            if ( i < h - 1 && town[i+1][j] != '#' && time[i+1][j] == INF ) {
                time[i+1][j] = time[i][j] + 1;
                x.push(i+1);
                y.push(j);
            }
            if ( j < w - 1 && town[i][j+1] != '#' && time[i][j+1] == INF ) {
                time[i][j+1] = time[i][j] + 1;
                x.push(i);
                y.push(j+1);
            }
        }

        getline(cin, str);

        long t = 1;
        int lenpat = str.length();
        while(t < lenpat * 1000) {
            switch(str[(t - 1) % lenpat]) {
                case '2':
                    if (gx < h - 1) gx += 1;
                    break;
                case '4':
                    if (gy > 0) gy -= 1;
                    break;
                case '6':
                    if (gy < w - 1) gy += 1;
                    break;
                case '8':
                    if (gx > 0) gx -= 1;
                    break;
            }
            if (time[gx][gy] <= t) {
                cout << t << " " << gx << " " << gy << endl; 
                break;
            }
            t += 1;
        }
        if (t == lenpat * 1000) {
            cout << "impossible" << endl;
        }

    }
     
    return 0;
}