/**< */#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <ctype.h>
#define N 310 using namespace std; int d[][] = {{-, -}, {-, }, {-, -}, {-, }, {, -}, {, }, {, -}, {, }};
int vis[N][N], l, ex, ey; struct node
{
int x, y, step;
}; int BFS(int x, int y)
{
queue<node>Q;
int i;
node now, next;
now.x = x;
now.y = y;
now.step = ;
vis[now.x][now.y] = ;
Q.push(now);
while(!Q.empty())
{
now = Q.front();
Q.pop();
if(now.x == ex && now.y == ey)
return now.step;
for(i = ; i < ; i++)
{
next.x = now.x + d[i][];
next.y = now.y + d[i][];
next.step = now.step + ;
if(next.x >= && next.x < l && next.y >= && next.y < l && !vis[next.x][next.y])
{
vis[next.x][next.y] = ;
Q.push(next);
}
}
}
return -;
} int main()
{
int t, sx, sy;
scanf("%d", &t);
while(t--)
{
memset(vis, , sizeof(vis));
scanf("%d", &l);
scanf("%d%d", &sx, &sy);
scanf("%d%d", &ex, &ey);
if(sx == ex && sy == ey)
printf("0\n");
else
printf("%d\n", BFS(sx, sy));
}
return ;
}