Geologic Strata

No attempts yetTime limit1sMemory limit128 MB

Problem

Time travel is finicky business. Occasionally you end up hundreds of millions of years away from when you intended. So as a time-traveling salesman, Tim often wants to verify that he has landed near his target date. This is easy when he travels forward in time, because there are always people around he can ask. Traveling back in time is a different story: humans have not been around for very long, much less kept track of time with calendars. For trips far into the past, Tim wants a new way to confirm which era he has landed in.

One strategy is to use the principles of geologic dating. By taking a core sample of earth where he lands, Tim can study the layers of sediment, called strata, each of which formed during a specific geologic period. Telling one stratum from another is easy, but it is impossible to say which geologic period a stratum belongs to from the sediment alone, because of local variations in climate and soil. This is where fossils come in. If a stratum contains a fossil, the corresponding geologic period is known, based on fossil records and the fact that every member of a species lived during the same geologic period. So to verify when he has landed, all Tim needs to know is whether the strata in the core sample are consistent with the target time he entered into his time machine.

Input

The first line contains the number of test cases $K$. Then follow $K$ test cases, each of the following form.

The first line of a test case contains three integers $t$, $w$, and $d$: Tim's target time (in millions of years ago), and the width and depth of the core sample, with $0 \le t \le 3000$ and $1 \le w, d \le 100$. The next $d$ lines each contain $w$ characters and describe the core sample. Each character is a digit (09) or a capital letter (AM).

A digit is sediment belonging to a particular stratum. Stratum 0 is the surface of the earth and therefore matches the geologic period of Tim's target time. Stratum 1 is the layer directly below stratum 0, stratum 2 the layer below stratum 1, and so on — each deeper stratum is one geologic period older than the one above it.

A capital letter is a fossil, and its label identifies a geologic period as in the table below.

PeriodRange (millions of years ago)Fossil label
Quaternary0 to 3A
Neogene4 to 23B
Paleogene24 to 66C
Cretaceous67 to 146D
Jurassic147 to 200E
Triassic201 to 251F
Permian252 to 299G
Carboniferous300 to 359H
Devonian360 to 416I
Silurian417 to 444J
Ordovician445 to 488K
Cambrian489 to 542L
Precambrian543 and olderM

A fossil belongs to the stratum immediately surrounding it, counting the eight neighbouring cells including diagonals. If a fossil touches more than one kind of stratum (for example both 1 and 2), it belongs to the stratum with the numerically lowest digit. No fossil is completely surrounded by other fossils, and every core sample contains at least one fossil and at least one stratum.

Output

For each test case, output Data Set x: on its own line, where x is the 1-based number of the test case. On the next line, output Yes if every fossil in the core sample is consistent with Tim's target time, and No otherwise. Separate consecutive test cases with a blank line.