Artistic Crystal Manufacture developed products named Crystal Jails. They are cool ornaments forming a rectangular solid. They consist of colorful crystal cubes. There are bright cores on the center of cubes, which are the origin of the name. The combination of various colored reflections shows fantastic dance of lights.
The company wanted to make big sales with Crystal Jails. They thought nice-looking color patterns were the most important factor for attractive products. If they could provide several nice patterns, some customers would buy more than one products. However, they didn't have staff who could design nice patterns. So they hired a temporary designer to decide the patterns.
The color pattern for mass production had a technical limitation: all cubes of the same color must be connected. In addition, they needed to send the pattern to the factory as a set of blocks, i.e. shapes formed by cubes of the same color. They requested him to represent the design in this form.
After a week of work, he sent various ideas of the color patterns to them. At first, his designs looked nice, but they noticed some patterns couldnft form a rectangular solid. He was a good designer, but they had not noticed he lacked space geometrical sense.
They didn't have time to ask him to revise his design. Although it was acceptable to ignore bad patterns, it also took a lot of time to figure out all bad patterns manually. So the leader of this project decided to ask you, a freelance programmer, for help.
Your task is to write a program to judge whether a pattern can form a rectangular solid. Note that blocks can be rotated.
The input consists of multiple datasets. Each dataset is formatted as follows:
W D H N
The first line of a dataset contains four positive integers W, D, H and N. W, D and H indicate the width, depth and height of a Crystal Jail. N indicates the number of colors.
The remaining lines describe N colored blocks. Each description is formatted as follows:
w d h
c111 c211 ... cw11
c121 c221 ... cw21
c1d1 c2d1 ... cwd1
c112 c212 ... cw12
c122 c222 ... cw22
c1d2 c2d2 ... cwd2
c11h c21h ... cw1h
c12h c22h ... cw2h
c1dh c2dh ... cwdh
The first line of the description contains three positive integers w, d and h, which indicate the width, depth and height of the block. The following (d + 1) × h lines describe the shape of the block. They show the cross-section layout of crystal cubes from bottom to top. On each height, the layout is described as d lines of w characters. Each character cxyz is either '*' or '.'. '*' indicates there is a crystal cube on that space, and '.' indicates there is not. A blank line follows after each (d × w)-matrix.
The input is terminated by a line containing four zeros.
You can assume the followings.
For each dataset, determine whether the given blocks can form a W × D × H rectangular solid and output "Yes" or "No" in one line.
3 3 3 5 3 2 2 *** .*. .*. ... 3 2 1 *** **. 3 1 3 ..* .** **. 3 2 2 ..* ... *** ..* 3 1 3 .** .** *** 3 3 3 2 3 3 3 *** *** *** *** *.* *** *** *** *** 1 1 1 * 3 2 1 2 3 1 1 *** 2 2 1 ** *. 0 0 0 0
Yes Yes No