The Problem

Jill, the new lab assistant has made new cages for the lab rabbits, Peter and Cottontail. Unfortunately, these new cages are more like mazes with walls in every direction. Help Arup determine if the rabbits are in the same section of the cage or different sections. Each rabbit can hop one square directly up, down, right or left. They can hop as many times as they want from one free square to another. Each rabbit must stay on the grid.

The Input

Each input will start with a single integer T (1 <= T <= 100) on the first line. The number T will denote the number of test cases that follow. Each test case will begin with two integers, R and C (1 <= R, C <= 10) separated by a space. Each of the next R lines will contain C characters of either _,#, P or C (Quotes for clarity). This will form a grid that represents the cage. A _ represents a cell free of obstructions, # represents a wall, P is Peters location and C is Cottontails location. Each grid is guaranteed to have one and only one P and C.

The Output

For each test case output a single line containing yes if Peter and Cottontail are in the same section of the cage and no if they are not in the same section of the cage.

Sample Input
4
2 2
P#
#C
2 2
P_
C_
8 7
__P____
####_##
_____#_
_____#C
##_###_
_____#_
___#_#_
___#___
5 7 __P
____ ##
##_## _
____#_
_____#C
##_###_
Sample Output
no
yes
yes
no
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.