object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  solve
  def solve: Unit ={
    val Array(h, w) = readLine.trim.split(' ').map(_.toInt)
    if (h == 0) return
    val state = Array.tabulate(h){_ ⇒ readLine.trim}
    val girl = state.indices.flatMap(h ⇒ state(h).indices.map{w ⇒ Coordinate(w, h)}).find{c ⇒ state(c.y)(c.x) == 'A'}.get
    val minTime = Array.tabulate(h){_ ⇒ Array.tabulate(w){_ ⇒ Int.MaxValue}}.also{arr ⇒ arr(girl.y)(girl.x) = 0}
    var current = List(girl)
    while (current.nonEmpty){
      var next = Nil: List[Coordinate]
      for {c ← current; n ← c.neighbor} {
        if ((0 until h).contains(n.y) && (0 until w).contains(n.x) && state(n.y)(n.x) != '#' && minTime(n.y)(n.x) > minTime(c.y)(c.x) + 1) {
          minTime(n.y)(n.x) = minTime(c.y)(c.x) + 1
          next ::= n
        }
      }
      current = next
    }
    val pattern = readLine.trim.map(_.asDigit).toArray
    var ghost = (state.indices.flatMap(h ⇒ state(h).indices.map{w ⇒ Coordinate(w, h)}).find{c ⇒ state(c.y)(c.x) == 'B'}.get, 0)
    var doubleGhost = (move(ghost._1, pattern(ghost._2 % pattern.length), h, w), (ghost._2 + 1) % pattern.length)
    var canContact = false
    while ((ghost._1 != doubleGhost._1 || ghost._2 % pattern.length != doubleGhost._2 % pattern.length) && !canContact){
      ghost = (move(ghost._1, pattern(ghost._2 % pattern.length), h, w), ghost._2 + 1)
      if (minTime(ghost._1.y)(ghost._1.x) <= ghost._2) {
        canContact = true
      }
      doubleGhost = (move(doubleGhost._1, pattern(doubleGhost._2), h, w), (doubleGhost._2 + 1) % pattern.length)
      doubleGhost = (move(doubleGhost._1, pattern(doubleGhost._2), h, w), (doubleGhost._2 + 1) % pattern.length)
    }
    var findReachable = false
    if (minTime(ghost._1.y)(ghost._1.x) != Int.MaxValue){
      findReachable = true
    }
    if (minTime(ghost._1.y)(ghost._1.x) <= ghost._2) {
      canContact = true
    }
    doubleGhost = ghost
    ghost = (move(ghost._1, pattern(ghost._2 % pattern.length), h, w), ghost._2 + 1)
    while (((ghost._1 != doubleGhost._1 || ghost._2 % pattern.length != doubleGhost._2 % pattern.length) || findReachable) && !canContact) {
      if (minTime(ghost._1.y)(ghost._1.x) != Int.MaxValue){
        findReachable = true
      }
      if (minTime(ghost._1.y)(ghost._1.x) <= ghost._2) {
        canContact = true
      }
      ghost = (move(ghost._1, pattern(ghost._2 % pattern.length), h, w), ghost._2 + 1)
    }
    println(
      canContact match {
        case true ⇒ s"${ghost._2 - 1} ${ghost._1.y} ${ghost._1.x}"
        case false ⇒ "impossible"
      }
    )
    solve
  }
  def move(coordinate: Coordinate, direction: Int, h: Int, w: Int): Coordinate = {
    (direction match {
      case 8 ⇒ Coordinate(0, -1) + coordinate
      case 6 ⇒ Coordinate(1, 0) + coordinate
      case 4 ⇒ Coordinate(-1, 0) + coordinate
      case 2 ⇒ Coordinate(0, 1) + coordinate
      case _ ⇒ coordinate
    }).let{c ⇒
      if ((0 until h).contains(c.y) && (0 until w).contains(c.x)) c
      else coordinate
    }
  }
  case class Coordinate(x: Int, y: Int) {
    def +(that: Coordinate): Coordinate = Coordinate(x + that.x, y + that.y)
    def neighbor: List[Coordinate] = List(Coordinate(x + 1, y), Coordinate(x - 1, y), Coordinate(x, y + 1), Coordinate(x, y - 1))
    def nextPosition: List[Coordinate] = this::neighbor
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
