Thomas has been learning origami lately and is experimenting with grid-based folding patterns. To get started, he has made creases in a rectangular piece of paper to split it up into an $$$m \times n$$$ grid. Thomas has marked two of the grid cells and wants to know the minimum number of creases he has to fold along in order to get one of the marked cells to lie directly on top of the other.
Each test consists of multiple test cases.
The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
The first line of each test case contains two integers, $$$m$$$ and $$$n$$$ ($$$1 \le m, n \le 1000$$$) — the number of rows and columns of the grid, respectively.
The next line of each test case contains four integers, $$$r_1$$$, $$$c_1$$$, $$$r_2$$$, and $$$c_2$$$ ($$$1 \le r_1, r_2 \le m$$$ and $$$1 \le c_1, c_2 \le n$$$) — the coordinates of the first and second marked cells, respectively, where $$$(1, 1)$$$ is the top left cell and $$$(n, m)$$$ is the bottom right cell. It is guaranteed that the two marked cells are different.
For each test case, output a single integer — the minimum number of crease folds required to land one of the marked cells on top of the other.
24 51 2 4 33 31 1 2 3
23
The first test case corresponds to the image above. Note that Thomas can only fold along the existing crease lines.
In the second test case, it can be proven that Thomas must make at least 3 folds.
| Название |
|---|


