409704: GYM103688 F 342 and Xiangqi

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. 342 and Xiangqitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

342 likes playing Xiangqi (as it's called Chinese chess). His favorite piece in Xiangqi is "Xiang" because his opponents usually overlook the existence of Xiang so their major pieces are often taken by 342's Xiang.

For those of you who don't know how Xiang moves in Xiangqi, Xiang is a minor piece that each player initially has two, located at the position 3 and 6 respectively. The number for each position is showed in the illustration bellow. In a single move, Xiang should move 2 squares horizontally as well as vertically. But note that it can neither move out of the half board nor it can overlap with other pieces. The illustration below showed all the 7 possible positions that Xiang could reach. For example, in a single move,

Centered scaled image.

· A Xiang at position 2 can move to position 4,

· A Xiang at position 7 can move to position 6,

· A Xiang at position 3 cannot move to position 5.

342 has 2 Xiangs as the only 2 pieces in the half board. Their present positions are given and guaranteed to be 2 different positions out of the 7 possible ones. But 342 disliked the present positions of his 2 Xiangs and would like to adjust their positions by a few moves. In each move, he can choose one of the Xiangs and move it following the rules explained. The final positions 342 want are also given and guaranteed to be 2 different positions out of the 7 possible ones. Note that the 2 Xiangs are considered the same, meaning that he doesn't restrict that which of the 2 Xiangs has to move to which of the 2 positions.

Now 342 wonders, at least how many moves he need to adjust the 2 Xiangs from the present positions to the final positions that 342 want?

Input

The first line contains a single integer $$$T~(1\leq T\leq 10^5)$$$ – the number of test cases.

This is followed by $$$T$$$ lines, representing each test case, each containing a single line of four integers $$$a_1,a_2,b_1,b_2$$$ such that $$$1\leq a_1,a_2,b_1,b_2 \leq 7,\ a_1\neq a_2,\ b_1\neq b_2$$$. $$$a_1, a_2$$$ represent the present positions of the 2 Xiangs while $$$b_1,b_2$$$ represent the final positions of them.

Output

For each test case, print a single integer: the least number of moves that 342 needs to adjust his 2 Xiangs to the final positions, considering the 2 Xiangs to be the same?

ExampleInput
3
1 5 1 7
2 7 4 6
2 3 3 2
Output
1
2
0

加入题单

算法标签: