High-End Artwork

Stamps are pressed onto a paper in a given order; later presses overwrite earlier ones. Print the final grid, using '.' for untouched cells.

Easy3SimulationArrayImplementationInterviewNo attempts yetTime limit4sMemory limit512 MB

Problem

Junha is a painter who builds pictures out of stamps. He prepares several stamps of different sizes and shapes, then presses them onto a sheet of paper at chosen spots, one after another.

Gangmin wants to copy that method exactly. Given which stamp is pressed and where, in order, print the finished picture.

The paper starts out blank. Pressing a stamp turns every cell the stamp covers into the character at the matching spot of the stamp. A cell that already holds an earlier stamp is covered by the later one.

Input

The first line contains the height NN and the width MM of the paper. (1N,M10001 \le N, M \le 1000)

The second line contains the number of stamps KK. (1K5001 \le K \le 500) The stamps follow in order, numbered 1 through KK. Each stamp starts with a line holding its height HH and width WW (1H,W5001 \le H, W \le 500), followed by HH lines of WW characters each that give the shape of the stamp. Every cell of a stamp is an English letter or a digit, so a period never appears inside a stamp.

The next line contains the number of presses QQ. (1Q100001 \le Q \le 10000) Each of the following QQ lines contains a stamp number TT and coordinates YY, XX, given in the order the presses happen. (1TK1 \le T \le K, 0Y,X10000 \le Y, X \le 1000)

YY and XX are the coordinates of the top left cell of the area the stamp covers. The top left cell of the paper is (0,0)(0, 0), YY counts down from the top and XX counts right from the left. No press ever reaches outside the paper.

Output

Print the finished paper on NN lines. Each line holds MM characters, and a cell that no stamp ever touched is printed as a period (.). The order of the presses must be visible in the result.