Under construction

Still being built. Things may change

Bull in a China Shop (Bronze)

Time limit2sMemory limit512 MB

Summary
Pick the two pieces from K candidates that shift without rotation to cover the original grid exactly once.
Level

Easy3 of 10

Topics
Brute force, Simulation
Solved
No attempts yet

Problem

Farmer John decided that his home needs more decoration. At the local china shop he finds a delicate glass cow figurine that fits perfectly on the mantel above his fireplace, so he decides to buy it.

The shape of the figurine is given as an N×NN \times N grid of characters (3≤N≤83 \le N \le 8). A '#' is a cell that belongs to the figurine and a '.' is a cell that does not. Here is an example with N=8N = 8.

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

Right before John can pay, a bull runs through the shop and breaks his figurine along with many other glass objects on the shelves. The figurine breaks into 2 pieces, and they end up mixed in with the KK pieces lying on the ground (3≤K≤103 \le K \le 10). Each of the KK pieces is given as an N×NN \times N grid of characters, in the same format as the figurine.

Find the two pieces John has to glue back together. The pieces were neither rotated nor flipped when they fell, so John only has to shift them horizontally and vertically and then lay one over the other. If the two pieces really came from his figurine, he can shift them so that every '#' of the original figurine belongs to exactly one of the two pieces: the shifted pieces share no '#', and together they form the original shape exactly.

A piece may be shifted by any amount horizontally and vertically, but it may not be shifted so far that one of its '#' characters leaves the N×NN \times N grid. The '#' characters of a piece do not have to form a single connected region. When a piece consists of several separate clumps, all of its clumps move by the same amount.

Input

The first line contains NN and KK, separated by a space. The next NN lines contain the grid of the original figurine. The following K×NK \times N lines contain the grids of the KK pieces John found on the ground, one piece after another.

Output

Print the indices of the two pieces of John's figurine on one line, separated by a space. Each index is between 11 and KK, and the smaller index comes first. A solution always exists and it is unique.

Examples1

  1. Example 1

    Input
    4 3
    ####
    #..#
    #.##
    ....
    .#..
    .#..
    ##..
    ....
    ####
    ##..
    #..#
    ####
    ....
    .###
    .#..
    .#..
    
    Expected output
    1 3