{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\r\n\t\u003cp\u003e\r\n\t\tLittle Tom loves playing games. One day he downloads a little computer game called \u0026#39;Bloxorz\u0026#39; which makes him excited. It\u0026#39;s a game about rolling a box to a specific position on a special plane. Precisely, the plane, which is composed of several unit cells, is a rectangle shaped area. And the box, consisting of two perfectly aligned unit cube, may either lies down and occupies two neighbouring cells or stands up and occupies one single cell. One may move the box by picking one of the four edges of the box on the ground and rolling the box 90 degrees around that edge, which is counted as one move. There are three kinds of cells, rigid cells, easily broken cells and empty cells. A rigid cell can support full weight of the box, so it can be either one of the two cells that the box lies on or the cell that the box fully stands on. A easily broken cells can only support half the weight of the box, so it cannot be the only cell that the box stands on. An empty cell cannot support anything, so there cannot be any part of the box on that cell. The target of the game is to roll the box standing onto the only target cell on the plane with minimum moves.\u003c/p\u003e\r\n\t\u003ccenter\u003e\r\n\t\t\u003cimg src\u003d\"http://poj.org/images/3322_1.JPG\" /\u003e\u003cbr /\u003e\r\n\t\tThe box stands on a single cell\u003c/center\u003e\r\n\t\u003ccenter\u003e\r\n\t\t\u003cimg src\u003d\"http://poj.org/images/3322_2.JPG\" /\u003e\u003cbr /\u003e\r\n\t\tThe box lies on two neighbouring cells, horizontally\u003c/center\u003e\r\n\t\u003ccenter\u003e\r\n\t\t\u003cimg src\u003d\"http://poj.org/images/3322_3.JPG\" /\u003e\u003cbr /\u003e\r\n\t\tThe box lies on two neighbouring cells, vertically\u003c/center\u003e\r\n\t\u003cp\u003e\r\n\t\tAfter Little Tom passes several stages of the game, he finds it much harder than he expected. So he turns to your help.\u003c/p\u003e\r\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\r\n\t\u003cp\u003e\r\n\t\tInput contains multiple test cases. Each test case is one single stage of the game. It starts with two integers \u003ci\u003eR\u003c/i\u003e and \u003ci\u003eC\u003c/i\u003e(3 \u0026le; R, C \u0026le; 500) which stands for number of rows and columns of the plane. That follows the plane, which contains \u003ci\u003eR\u003c/i\u003e lines and \u003ci\u003eC\u003c/i\u003e characters for each line, with \u0026#39;O\u0026#39; (Oh) for target cell, \u0026#39;X\u0026#39; for initial position of the box, \u0026#39;.\u0026#39; for a rigid cell, \u0026#39;#\u0026#39; for a empty cell and \u0026#39;E\u0026#39; for a easily broken cell. A test cases starts with two zeros ends the input.\u003c/p\u003e\r\n\t\u003cp\u003e\r\n\t\tIt guarantees that\u003c/p\u003e\r\n\t\u003cul\u003e\r\n\t\t\u003cli\u003e\r\n\t\t\tThere\u0026#39;s only one \u0026#39;O\u0026#39; in a plane.\u003c/li\u003e\r\n\t\t\u003cli\u003e\r\n\t\t\tThere\u0026#39;s either one \u0026#39;X\u0026#39; or neighbouring two \u0026#39;X\u0026#39;s in a plane.\u003c/li\u003e\r\n\t\t\u003cli\u003e\r\n\t\t\tThe first(and last) row(and column) must be \u0026#39;#\u0026#39;(empty cell).\u003c/li\u003e\r\n\t\t\u003cli\u003e\r\n\t\t\tCells covered by \u0026#39;O\u0026#39; and \u0026#39;X\u0026#39; are all rigid cells.\u003c/li\u003e\r\n\t\u003c/ul\u003e\r\n\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e\r\n\tFor each test cases output one line with the minimum number of moves or \u0026quot;Impossible\u0026quot; (without quote) when there\u0026#39;s no way to achieve the target cell.\u003c/p\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e\r\n7 7\r\n#######\r\n#..X###\r\n#..##O#\r\n#....E#\r\n#....E#\r\n#.....#\r\n#######\r\n0 0\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e\r\n10\u003c/pre\u003e"}}]}