Pushing Boxes
Description
Imagine you arestanding inside a two-dimensional maze composed of square cells which may ormay not be filled with rock. You can move north, south, east or west one cellat a step. These moves are called walks.
One of the empty cells contains a box which can be moved to an adjacent freecell by standing next to the box and then moving in the direction of the box.Such a move is called a push. The box cannot be moved in any other way than bypushing, which means that if you push it into a corner you can never get it outof the corner again.
One of the empty cells is marked as the target cell. Your job is to bring thebox to the target cell by a sequence of walks and pushes. As the box is veryheavy, you would like to minimize the number of pushes. Can you write a programthat will work out the best such sequence?
Input
The input containsthe descriptions of several mazes. Each maze description starts with a linecontaining two integers r and c (both <= 20) representing the number of rowsand columns of the maze.
Following this are r lines each containing c characters. Each characterdescribes one cell of the maze. A cell full of rock is indicated by a `#' andan empty cell is represented by a `.'. Your starting position is symbolized by`S', the starting position of the box by `B' and the target cell by `T'.
Input is terminated by two zeroes for r and c.
Output
For each maze inthe input, first print the number of the maze, as shown in the sample output.Then, if it is impossible to bring the box to the target cell, print ``Impossible.''.
Otherwise, output a sequence that minimizes the number of pushes. If there ismore than one such sequence, choose the one that minimizes the number of totalmoves (walks and pushes). If there is still more than one such sequence, anyone is acceptable.
Print the sequence as a string of the characters N, S, E, W, n, s, e and wwhere uppercase letters stand for pushes, lowercase lett