- bfs 순회 + 나이트의 이동 규칙에 따라 dx, dy list 변경
import sys
from collections import deque
dx = [1, 2, 2, 1, -1, -2, -2, -1]
dy = [2, 1, -1, -2, -2, -1, 1, 2]
def bfs(src_x, src_y, dest_x, dest_y):
queue = deque([]); queue.append([src_x, src_y])
while queue:
x, y = map(int, queue.popleft())
if x == dest_x and y == dest_y:
return
for i in range(8):
nx = x + dx[i]; ny = y + dy[i]
if nx < 0 or ny < 0 or nx >= I or ny >= I:
continue
if Map[nx][ny] == 0:
Map[nx][ny] = Map[x][y] + 1
queue.append([nx, ny])
T = int(input())
for _ in range(T):
I = int(input())
src = list(map(int, sys.stdin.readline()[:-1].split(' ')))
dest = list(map(int, sys.stdin.readline()[:-1].split(' ')))
Map = [[0] * I for i in range(I)]
bfs(src[0], src[1], dest[0], dest[1])
print(Map[dest[0]][dest[1]])