Board Silly

Time limit1sMemory limit128 MB

Problem

You are writing part of a board-game engine. Given a board layout and a player, you must enumerate every legal move for that player.

The game is played on an $8 \times 8$ grid of identical squares. Rows are labeled A through H from top to bottom, and columns are labeled 1 through 8 from left to right, so each square is named by its row letter followed by its column number (for example, A1 is the top-left square and H8 is the bottom-right square).

There are two players, whose pieces are written X and O (the letter "oh", not the digit zero). At any moment each player has between 1 and 12 pieces on the board. A move obeys the following rules:

  1. A piece moves in a straight line — left, right, up, down, or along either diagonal.
  2. The number of squares a piece moves equals the total number of pieces (of both players) currently in the row, column, or diagonal along which it is moving. A piece must move by exactly that number of squares — no more, no less.
  3. A piece may jump over pieces belonging to its own player.
  4. A piece may not jump over an opposing player's piece.
  5. A piece may capture an opposing piece by landing on it.
  6. A piece may not land on a square that is already occupied by one of its own player's pieces.

Input

The input contains one or more board layouts. Each layout is 8 lines of 8 characters; every character is X, O, or . (a period), where X and O mark occupied squares and . marks an empty square. Immediately after each board comes a single line containing one character, X or O, naming the player whose moves must be listed. The input ends at end of file.

Output

For each board, print every legal move for the named player, one move per line. Each line gives the origin square and the destination square, in that order, joined by a single hyphen - (for example, A1-B2); each square is written as its row letter followed by its column number. If the player has no legal move on that board, print No moves are possible instead. Separate the output of consecutive boards with a single blank line.

So that the output is uniquely determined, list the moves in this exact order: scan the squares of the board top to bottom, and within each row from left to right; for each of the named player's pieces, test the eight directions in this clockwise order — up, up-right, right, down-right, down, down-left, left, up-left — and emit each legal move in the order it is found.