#C10659. Path Finding in a Grid

    ID: 39888 Type: Default 1000ms 256MiB

Path Finding in a Grid

Path Finding in a Grid

You are given a grid consisting of R rows and C columns. Each cell in the grid is either open (represented by '.') or blocked (represented by '*'). Your task is to determine if there exists a path from the top-left cell (1,1) to the bottom-right cell (R,C). You can move in four cardinal directions: up, down, left, and right. A move is considered valid if it stays within the grid bounds, i.e., $$0 \leq i < R$$ and $$0 \leq j < C$$, where $$i$$ and $$j$$ denote the row and column indices (0-indexed), respectively.

If a valid path exists, print YES; otherwise, print NO.

inputFormat

The first line of input contains an integer T representing the number of test cases. Each test case is described as follows:

  • The first line of each test case contains two integers R and C — the number of rows and columns in the grid.
  • The next R lines each contain a string of length C consisting only of the characters '.' and '*', representing an open or blocked cell respectively.

All input is read from standard input (stdin).

outputFormat

For each test case, output a single line containing YES if there exists a path from the top-left cell to the bottom-right cell, or NO if no such path exists. Output all answers to standard output (stdout).

## sample
4
3 3
.*.
.*.
...
2 2
**
.*
3 3
...
...
...
2 2
..
*.
YES

NO YES YES

</p>