Bull in a China Shop (Bronze)#10569

Bull in a China Shop (Bronze)

1 second
128 megabytes
Medium

Farmer John has decided that his home needs some more decoration. While visiting a local china shop, he finds a delicate glass cow figurine that he decides to purchase, knowing that it will fit perfectly on the mantel above his fireplace.

The shape of the cow figurine is described by an n \times n grid of characters, like the one below. The '#' characters are part of the figurine, while the '' characters are not.

...............
...............
...............
#..#...........
####...........
############...
.##.#########..
....#######.##.
....##...##....
....##...##....
...............
...............
...............
...............
...............

Unfortunately, just before FJ can make his purchase, a bull runs through the shop and breaks not only FJ's figurine, but many of the other glass objects on the shelves as well! FJ's figurine breaks into pieces, which quickly become lost among the total pieces scattered on the ground. Each of the pieces is described by an n \times n grid of characters, just like the original figurine.

Please help FJ determine which two of the pieces belong to his figurine. Fortunately, when the two pieces fell to the ground, they were neither rotated nor flipped. Therefore, to reassemble the figurine, FJ only needs to shift the pieces horizontally and/or vertically and then superimpose them. If he has the correct two pieces, he should be able to position them so that they exactly reconstruct the original figurine: every '#' in the original figurine must be represented by exactly one of the two pieces. In other words, after shifting and superimposing the two pieces, they must not overlap on any '#' characters, and their union must exactly match the original shape.

FJ may shift a piece horizontally and/or vertically by any number of cells, as long as none of its '#' characters fall outside the original n \times n grid. The shape of a piece does not necessarily consist of a single connected region of '#' characters. Nevertheless, if a piece consists of multiple disjoint groups of '#' characters, all of them must be shifted by the same amount when the piece is moved.

Input

The first line contains two integers n~(3 \le n \le 8) and k~(3 \le k \le 10). The next lines describe the grid of characters representing FJ's original figurine. The following k \cdot n lines describe the grids of characters representing the pieces FJ finds on the ground.

Output

Print two integers, each in the range , specifying the indices of the two pieces that belong to FJ's figurine. A solution will always exist and will be unique. The two indices must be printed in sorted order.

Examples

Example 1

Loading
Loading