Minecraft Redstone

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 10M

Author:
Problem types

Jonathan Sumabat

After realizing that Jonathan Sumabat sucks at osu!, Jonathan Sumabat switches to the superior Minecraft: a game where Jonathan Sumabat can build anything that Jonathan Sumabat can imagine. The most important aspect of Minecraft, of course, is that it has a singleplayer mode, so that Jonathan Sumabat's friends can't make fun of Jonathan Sumabat for being bad at the game. Jonathan Sumabat, still wishing to fulfill Jonathan Sumabat's destiny of becoming the BEST programmer in the universe, decides to try programming in Minecraft itself. This is done by using something called Redstone Dust, which is a conductive powder that can be placed on the ground and can transport a current of electricity throughout its path. Generating electricity in Minecraft is awfully easy, and in fact, it can be accomplished with the single push of a button. Jonathan Sumabat can place a button anywhere on an W by L grid, where W represents the width of the grid, and L represents the length. Jonathan Sumabat's objective is to light a lamp with Jonathan Sumabat's circuit, which he also places on another point in the grid. To connect the button and the lamp, Jonathan Sumabat blindly sprinkles some Redstone Dust on the grid, hoping that Jonathan Sumabat's circuit works. For Redstone Dust to transmit a signal, it must connect to other Redstone Dust, a button, or a lamp either horizontally or vertically. Redstone Dust cannot transmit any signal diagonally.

Because Jonathan Sumabat lacks basic comprehension skills, Jonathan Sumabat has asked you to analyze some of Jonathan Sumabat's circuits and determine whether the button will successfully turn on the lamp in each case.

On the grid, the button will be represented as B, the lamp as L, the Redstone Dust as #, and the emptiness (such as in Jonathan Sumabat's heart) will be represented as .. It is guaranteed that there will be exactly one button and one lamp on each grid.

The following is a valid circuit sample:

B...
##..
.#..
.##L

In the sample, the redstone dust (#) connects the button (B) and the lamp (L) together, therefore completing the circuit.

Note that a button can directly power a lamp if it is directly beside it, therefore

....
.BL.
....

is considered to be a working circuit.

Input Specification

The first line of input will contain an integer N (1 \le N \le 50), denoting the number of circuits that Jonathan Sumabat wants you to look at.

Each circuit consists of two space-separated integers, W and L (2 \le W, L \le 50), where W represents the width of the grid, and L represents the length. These integers are followed by a W by L grid consisting of exactly one button (B), one lamp (L), and a whole lot of Redstone Dust (#) and emptiness (.). Every single test case will be separated by a newline.

Output Specification

For each case, output on a new line whether Jonathan Sumabat's circuit will function. If the lamp is successfully turned on, output YES. If no, output NO.

Sample Input

4
6 8
B.....
######
.....#
....##
...##.
..##..
.##...
#####L

6 4
......
.B....
....L.
......

2 3
B.
#.
L.

5 3
.L..#
.##..
#..B.

Sample Output

YES
NO
YES
NO

Explanation

In the first circuit, the Z-shaped Redstone path connects the button (at the top left of the grid) and the lamp (at the bottom right of the grid), completing the circuit.

In the second circuit, there is no Redstone Dust connecting the button and the lamp, and since they are not directly adjacent to one another, the lamp will not turn on.

In the third circuit, there is one unit of Redstone Dust connecting the button and the lamp, completing the circuit.

In the last circuit, the Redstone Dust path connected to the lamp is not connected to the button, as Redstone Dust must be directly adjacent (and not horizonatal) to the button/lamp to transmit signal. Therefore, the lamp will not turn on.


Comments

There are no comments at the moment.