#C7461. Knight Moves: Exact Reachability

    ID: 51335 Type: Default 1000ms 256MiB

Knight Moves: Exact Reachability

Knight Moves: Exact Reachability

You are given an M x N chessboard, along with the starting position of a knight and a target position. Determine if the knight can reach the target position in exactly K moves. The knight moves in an "L" shape as in standard chess: two squares in one direction and one square perpendicular to that direction. Your task is to decide whether it is possible for the knight to reach the target in exactly K moves using valid knight moves on the board.

The movement of the knight can be described using the following moves in \(\LaTeX\):

\[ \begin{array}{cc} (2,1), & (2,-1), \\ (-2,1), & (-2,-1), \\ (1,2), & (1,-2), \\ (-1,2), & (-1,-2)\ \end{array} \]

Note that the knight must remain within the boundaries of the board where the rows range from 0 to \(M-1\) and the columns from 0 to \(N-1\).

inputFormat

The first line of the input contains an integer T representing the number of test cases. Each of the following T lines describes a test case containing seven space-separated integers: M N x_start y_start x_target y_target K, where:

  • M is the number of rows in the chessboard.
  • N is the number of columns in the chessboard.
  • x_start and y_start represent the starting coordinates of the knight.
  • x_target and y_target represent the target coordinates of the knight.
  • K is the exact number of moves allowed.

All input is read from stdin.

outputFormat

For each test case, output a single line containing YES if the knight can reach the target position in exactly K moves, and NO otherwise. The result for each test case should be printed on a new line to stdout.

## sample
3
8 8 0 0 1 2 1
8 8 0 0 7 7 6
8 8 0 0 7 7 7
YES

YES NO

</p>