In the room, parquet flooring is to be installed, and there is a plan to create a specific pattern on the floor.
The parquet tiles are made up of 1 \times 1 squares, each of which can be either white or black. The room itself has dimensions of N \times M. The room's layout specifies the desired color for each square.
There are several shapes of parquet tiles available:

Each square within a single parquet tile can have a different color. There can be multiple types of tiles with the same shape but different color patterns. Tiles of different types may also have different costs. The supply of each type of tile is unlimited. Tiles can be rotated by degrees. Tiles cannot be broken or placed face down.
Initially, some parts of the floor may already be covered with tiles.
Your task is to determine the minimum total cost required to cover the remaining part of the room with tiles.
The first line of the input contains three numbers: , (the dimensions of the room), and (the number of available tile types), where 1 \leq N, M \leq 8, 1 \leq K \leq 10. After that follows the description of the required floor coloring. This description consists of rows with numbers in each, where represents white, — black, and denotes a square already covered with a tile. The last rows describe the available types of tiles in the following format:
<shape> <cost> <color>
<shape> is an integer from to indicating the shape of the tile (see the image above).
<cost> is a natural number not exceeding , representing the cost of one tile of this type.
<color> is a sequence of one to three numbers, each either or . The count of numbers corresponds to the number of squares in the tile. These numbers specify the colors of the squares in the tile, following the numbering in the image.
Output a single number — the minimum cost required to cover the floor as specified, or –1 if it is impossible to place tiles as required.
Example 1