Under construction

Still being built. Things may change

Prison Break

Time limit2sMemory limit512 MB

Summary
Given a grid of '+' and '*' huts where movement is allowed only between huts of the same symbol, decide whether the entry hut can reach the exit hut.
Level

Easy3 of 10

Topics
Graph, BFS, Matrix
Solved
No attempts yet

Problem

A prison is built as a labyrinth. The labyrinth is made of huts, and every hut is marked + or *. Two huts are neighbors when they share a side. From a + hut the prisoner moves only to a neighboring + hut, and from a * hut only to a neighboring * hut.

The labyrinth is a rectangle of length LL and width WW. A hut is identified by a horizontal position and a vertical position. Horizontal positions run from 11 to LL starting at the left, and vertical positions run from 11 to WW starting at the bottom.

Every hut of the labyrinth is an entry hut, but there is only one exit hut. You are given the labyrinth, the entry hut where the prisoner stands, and the exit hut. Decide whether the prisoner can reach the exit hut.

Input

The first line contains the number of test cases PP.

The first line of each test case contains six natural numbers LL, WW, AA, BB, CC, DD separated by spaces.

  • LL is the length of the labyrinth and WW is its width.
  • AA and BB are the horizontal and vertical positions of the entry hut where the prisoner stands.
  • CC and DD are the horizontal and vertical positions of the exit hut.

Then follow WW lines of LL characters each. Every character is + or *. The lines are given from the top of the labyrinth downward, so the ii-th line describes the huts whose vertical position is W+1−iW+1-i.

1≤P≤201 \le P \le 20, 1≤L≤5001 \le L \le 500, 1≤W≤5001 \le W \le 500, 1≤A,C≤L1 \le A, C \le L, 1≤B,D≤W1 \le B, D \le W, and the sum of L×WL \times W over all test cases is at most 250000250000.

Output

For each prison print YES if the prisoner can escape and NO otherwise, one answer per line.

Examples2

  1. Example 1

    Input
    2
    4 2 1 2 4 1
    ++**
    *+++
    3 2 2 2 3 1
    +*+
    *+*
    
    Expected output
    YES
    NO
    
  2. Example 2

    Input
    2
    6 1 1 1 6 1
    ++++++
    6 1 1 1 6 1
    +++*++
    
    Expected output
    YES
    NO