The Walk

3.6

33 votes
Problem

Sunny is playing a game with his friend Akshara . In this game he is inside a 4 x 4 Matrix , and akshara gives sunny a initial position and a final position . Sunny is standing at the initial position and he has to reach the final position by using minimum number of steps.

Rules : He can move only diagonally.This is 4 X 4 Matrix and these are the position.

This is the 4 X 4 Matrix

Input :

The first line contains T- number of test cases. The next line contains two inputs I-initial position and F - final position.

Output :

For each test case output the minimum no of steps to reach the final position.

Constraints :

1<=T<=50

1<=(I,F)<=16

Note : If sunny is not able to reach the final position you need to print No, and if the initial and final positions are same Output will be 0.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first case : He need to use a single step to reach 7.

In the second case : first he jumps to 6 and then he jumps to 3 . Only two steps are used.

In the third case : He cannot reach 9 so output is No (remember he only moves diagonally ).

Editor Image

?