Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	dy := [4]int{-1, 0, 0, 1}
	dx := [4]int{0, -1, 1, 0}
	for {
		h := getNextInt(scanner)
		w := getNextInt(scanner)
		if h == 0 {
			break
		}
		grid := makeGrid(h, w)
		a := [2]int{}
		b := [2]int{}
		for i := 0; i < h; i++ {
			s := getNextString(scanner)
			for j := 0; j < w; j++ {
				if s[j] == '#' {
					grid[i][j] = math.MaxInt32
					continue
				}
				if s[j] == 'A' {
					a[0] = i
					a[1] = j
					continue
				}
				if s[j] == 'B' {
					b[0] = i
					b[1] = j
				}
				grid[i][j] = math.MaxInt32 - 1
			}
		}
		q := make([][2]int, 0)
		q = append(q, a)
		for len(q) > 0 {
			p := q[0]
			q = q[1:]
			for i := 0; i < 4; i++ {
				yy := p[0] + dy[i]
				xx := p[1] + dx[i]
				if yy == a[0] && xx == a[1] {
					continue
				}
				if yy < 0 || yy >= h {
					continue
				}
				if xx < 0 || xx >= w {
					continue
				}
				if grid[yy][xx] == math.MaxInt32 {
					continue
				}
				if grid[yy][xx] <= grid[p[0]][p[1]]+1 {
					continue
				}
				grid[yy][xx] = grid[p[0]][p[1]] + 1
				q = append(q, [2]int{yy, xx})
			}
		}
		move := getNextString(scanner)
		i := 0
		m := len(move)
		for {
			if i > 400 {
				fmt.Fprintln(writer, "impossible")
				break
			}
			if grid[b[0]][b[1]] <= i {
				fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i, b[0], b[1]))
				break
			}
			switch move[i%m] {
			case '8':
				if b[0] > 0 {
					b[0]--
				}
			case '6':
				if b[1]+1 < w {
					b[1]++
				}
			case '4':
				if b[1] > 0 {
					b[1]--
				}
			case '2':
				if b[0]+1 < h {
					b[0]++
				}
			}
			i++
		}
	}
}
func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int h,w;
string data[30];
bool visited[30][30];
int dist[30][30];

void dfs(int y,int x){
	if( y<0 || h<=y || x<0 || w<=x || visited[y][x]==true || data[y][x]=='#' )return ;

	visited[y][x]=true;

	int left=INF,right=INF,up=INF,down=INF;
	if(x-1>=0) left  = dist[y][x-1]+1;
	if(y-1>=0) up 	 = dist[y-1][x]+1;
	if(x+1<w ) right = dist[y][x+1]+1;
	if(y+1<h ) down  = dist[y+1][x]+1;

	dist[y][x] = min( dist[y][x] , min( min(left,right) , min(up,down) ) );


	dfs(y,x+1);
	dfs(y,x-1);
	dfs(y+1,x);
	dfs(y-1,x);

}


int main(){
	while(cin>>h>>w){
		if(h==0&&w==0)break;

		string move;
		int sx,sy,gx,gy;
		rep(i,30)rep(j,30)visited[i][j]=false;
		rep(i,30)rep(j,30)dist[i][j]=INF;

		rep(i,h)cin>>data[i];
		cin>>move;

		rep(i,h)rep(j,w){
			if(data[i][j]=='A'){
				sy=i;sx=j;
				data[i][j]='.';
			}
			if(data[i][j]=='B'){
				gy=i;gx=j;
				data[i][j]='.';
			}
		}

		dist[sy][sx]=0;
		dfs(sy,sx);

		for(int i=0;;i++){
			if(dist[gy][gx]<=i){
				cout<<i<<" "<<gy<<" "<<gx<<endl;
				break;
			}

			if(i>=1000000){
				cout<<"impossible"<<endl;
				break;
			}

			if(move[i%move.size()]=='5');
			if(move[i%move.size()]=='8')if(0<=gy-1)gy--;
			if(move[i%move.size()]=='6')if(gx+1<w) gx++;
			if(move[i%move.size()]=='4')if(0<=gx-1)gx--;
			if(move[i%move.size()]=='2')if(gy+1<h) gy++;
		}
	}

}


/*
'5'	????????´????????????
'8'	??????1????????????
'6'	??±???1????????????
'4'	?\????1????????????
'2'	??????1????????????
*/

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <fstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


main(){
  int h,w;
  while(cin>>h>>w,h|w){
    string in[h],pa;
    int sx,sy,bx,by;
    rep(i,h){
      cin>>in[i];
      rep(j,w){
	if(in[i][j]=='A'){
	  sx=i;
	  sy=j;
	  in[i][j]='.';
	}
	if(in[i][j]=='B'){
	  bx=i;
	  by=j;
	  in[i][j]='.';
	}
      }
    }
    cin>>pa;


    int cost[h][w];
    rep(i,h)rep(j,w)cost[i][j]=INT_MAX/2;

    queue<PI> Q;
    Q.push(mp(0,sx*1000+sy));

    while(!Q.empty()){
      int cc=Q.front().F,cx=Q.front().S/1000,cy=Q.front().S%1000;
      Q.pop();
      //cout<<cx<<" "<<cy<<endl;
      if(cost[cx][cy]<=cc)continue;
      cost[cx][cy]=cc;

      rep(i,4){
	int nx=cx+dx[i],ny=cy+dy[i];
	if(nx<0 || h<=nx || ny<0 || w<=ny || in[nx][ny]=='#'){
	  continue;
	}
	Q.push(mp(cc+1,1000*nx+ny));
      }
    }

    int ans=-1,ax,ay;
    set<int> app[h][w];
    int po=0;
    int time=0;
    int imp=0;

    while(true){
      if(cost[bx][by]<=time){
	ans=time;
	ax=bx;
	ay=by;
	break;
      }

      if(app[bx][by].count(po)){
	break;
      }

      if(cost[bx][by]==INT_MAX/2){
	imp++;
      }

      if(cost[bx][by]==INT_MAX/2 && imp>=pa.size()){
	app[bx][by].insert(po);
      }
      
      int px=bx,py=by;
      switch(pa[po]){
      case '8':
	bx--;
	break;
      case '6':
	++by;
	break;
      case '4':
	--by;
	break;
      case '2':
	++bx;
	break;
      }
      if(bx<0 || h<=bx || by<0 || w<=by){
	bx=px;
	by=py;
      }
      ++time;
      ++po;
      if(po>=pa.size()){
	po=0;
	if(imp<pa.size())imp=0;
      }
    }
    if(ans==-1)cout<<"impossible";
    else cout<<ans<<" "<<ax<<" "<<ay;
    cout<<endl;
  }
}