flood-fill-algorithm

There is a robot named Micro in a matrix A, of integers of size N \times M, initially placed at the cell (X_1, Y_1). He has to rescue his princess Mini placed at cell  (X_2, Y_2). Rows are numbered from 1 to N and columns are numbered from 1 to M. He can move one step in either of the four directions: up, down, left and right. Also he can make a move if value at cell he is currently at is strictly less than the value at cell he is moving to. Help Micro find out if he can rescue his princess or not.

Input:
First line consists of T the number of test case.
In each test case first line consists of six space separated integers denoting N, M, X_1, Y_1, X_2, Y_2 . Then N lines follow each consisting of M space separated integers denoting the matrix.

Output:
For each test case, print in a new line, "YES" (without quotes) if Micro can rescue Mini otherwise print "NO" (without quotes).

Constraints:
 1≤ T ≤ 5
1 ≤ N, M  ≤ 10 
1 ≤ X_1, X_2  ≤ N  
1 ≤ Y_1, Y_2  ≤ M  
1 ≤ A[i][j] ≤ 100 

SAMPLE INPUT
2
2 2 1 1 2 2
2 1
1 3
3 3 1 1 2 3
2 1 1
3 2 7
4 5 6

SAMPLE OUTPUT
NO
YES

Source: hackerearth | Difficulty: EASY


Solutions: