405889: GYM102152 G The Special King

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

Description

G. The Special Kingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Assem bought a new chess board that has a special king that move in a different way than other regular kings.

In one move, the special king can move from its position in one of the following directions: up, down, left, or right. Formally, if the special king is standing on position ($$$x$$$, $$$y$$$), in one move it can go to one of the following positions: ($$$x - 1$$$, $$$y$$$), ($$$x + 1$$$, $$$y$$$), ($$$x$$$, $$$y - 1$$$), or ($$$x$$$, $$$y + 1$$$).

Initially, the special king is standing on position ($$$x_1$$$, $$$y_1$$$) and Assem wants to place it on position ($$$x_2$$$, $$$y_2$$$). Can you help Assem by calculating the minimum number of required moves he needs to accomplish his goal?

Input

The first line contains an integer $$$T$$$ ($$$1 \le T \le 4096$$$) specifying the number of test cases,

Each test consists of a single line containing four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, and $$$y_2$$$ ($$$1 \le x_1, y_1, x_2, y_2 \le 8$$$), in which $$$x_1$$$ and $$$y_1$$$ are representing the starting position of the special king, and $$$x_2$$$ and $$$y_2$$$ are representing the the ending position.

Output

For each test case, print a single line containing the minimum number of required moves to move the special king from the starting position to the ending position.

ExampleInput
3
1 3 4 2
5 7 3 1
3 2 3 2
Output
4
8
0
Note

In the first test case, the special king needs to be moved from position ($$$1$$$, $$$3$$$) to ($$$4$$$, $$$2$$$). One possible solution is to make $$$3$$$ moves down to position ($$$4$$$, $$$3$$$), then make $$$1$$$ move to the left to position ($$$4$$$, $$$2$$$). So, the total number of moves is $$$4$$$.

加入题单

算法标签: