#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int,int>PII;
typedef pair<PII,int>PIII;
const int N = 305;
bool g[N][N];
int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
int n;
int sx, sy, ex, ey;
int bfs(){
memset(g, false, sizeof g);
queue<PIII>q;
q.push({{sx, sy}, 0});
g[sx][sy] = true;
while(q.size()){
PIII st = q.front();
q.pop();
PII u = st.first;
int dist = st.second;
for(int i = 0; i < 8; i ++ ){
int a = dx[i] + u.first, b = dy[i] + u.second;
if(a >= 0 && b >= 0 && a < n && b < n && !g[a][b]){
q.push({{a, b}, dist + 1});
if(a == ex && b == ey) return dist + 1;
g[a][b] = true;
}
}
}
return 0;
}
int main(){
int T;
cin>>T;
while(T -- ){
cin>>n;
cin>>sx>>sy>>ex>>ey;
cout<<bfs()<<'\n';
}
return 0;
}