Stained Glass

Time limit1sMemory limit128 MB

Problem

Dale was working on the restoration of an elaborate stained glass window composed of numerous irregular pieces of colored glass. He had carefully disassembled the window, treated the more faded pieces of glass to restore their bright coloring, and had made substantial progress toward reassembling the work when night fell and the poor lighting forced him to stop.

Upon returning the next morning, he discovered that some well-meaning janitor had disposed of his drawings and pictures of the original window. Now he has to figure out how to arrange the pieces to fit the hole remaining in the window. Because of the techniques used to prepare ancient stained glass, the glass was not of uniform thickness but was always cut and arranged so that the thickest edge would be at the bottom. He therefore knows the vertical orientation of each piece (they may not be rotated) but not the facing, so some pieces may need to be flipped horizontally.

Decide whether all of the pieces can be placed, each flipped horizontally if needed and translated only, without overlapping, so that they exactly and completely fill the silhouette of the hole. Every piece must be used exactly once; rotating a piece or flipping it vertically is not allowed.

Input

Input consists of multiple datasets, terminated by a line containing the left-justified string ***.

Each dataset consists of silhouettes of one or more pieces and a silhouette of the hole in the window. A silhouette is an ASCII graphic composed of blanks and a specific non-blank character. A blank character indicates a location where no glass exists; the non-blank characters indicate the presence of glass (or, for the hole's silhouette, a location where glass is to be placed).

Each silhouette consists of 1 to 8 lines, each line containing 1 to 8 characters, and every line has at least one non-blank character. Each silhouette is presented as a separate group of lines.

The first piece is rendered using the character A, the next with B, and so on. There are at most 8 pieces. After the final piece, the silhouette of the hole is rendered using the character #. The transition from one silhouette to the next is signalled by the change of character. The end of the hole's silhouette, and of the dataset, is signalled by an empty line.

Output

For each dataset, print a line containing ===== (5 equal signs). Then, if the pieces can be placed (each flipped horizontally if needed and translated only, without overlapping, using every piece exactly once) so that they exactly and completely fill the hole's silhouette, print The window can be repaired.. If no such arrangement is possible, print The window cannot be repaired..