Fantasmagorie#10734

Fantasmagorie

1 second
128 megabytes
Very hard

Émile's dreams often feature people or animals morphing into others. Émile would like to show everyone the enchanting world of his dreams by creating the very first animated cartoon, in black and white, of course. After waking up, Émile only remembers the initial and final forms appearing in his dream, not the transformation itself, so he's asking you to reproduce these "morphings" by detailing the steps taken to transform the first image into the second.

The images in Émile's dreams are not just any black-and-white images; they obey the following three constraints.

First, all pixels on the border of the image — the leftmost and rightmost columns, and the top and bottom rows — have the same color.

Second, the image does not contain any 2 \times 2 square of the form

The third constraint is more complex and can be described as follows. Partition the image into regions, where a region is a connected monochromatic area — that is, the finest partition such that any two adjacent pixels of the same color are in the same region. Two regions are considered adjacent if they contain adjacent pixels. In Émile's images, every region is adjacent to at most two other regions, and the region containing the border pixels is adjacent to at most one other region.

You are given two black-and-white images of the same size w \times h, and your goal is to find a "morphing" transforming the first image into the second one. A morphing from image to image is a sequence of images starting with and ending with such that:

Input

The first line contains two space-separated integers (1 \le w \le 103) and (1 \le h \le 64). The next lines describe the first image, given row by row from top to bottom. Each of these lines consists of characters representing a row: the -th character is '.' if the -th pixel is white, and it is '\#' if that pixel is black. The following lines describe the second image, in the same format.

Émile's first and last images are distinct from each other.

Output

If no morphing exists, print IMPOSSIBLE. Otherwise, describe one possible morphing as follows: if the (k + 1)-th image is obtained from the -th image by flipping the pixel in column and row (where 0 \le c < w and 0 \le r < h, with c = 0 representing the leftmost column and r = 0 the topmost row), then the -th output line should contain the pair .

The output should contain at most pixel flips.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading