#include <iostream> #include <queue> using namespace std; class P { public: int x; int y; int d; P(int x = -1, int y = -1, int d = 0):x(x),y(y),d(d){} /* P& operator=(const P& p1) { x = p1.x; y = p1.y; d = p1.d; return *this; } */ }; queue<P> q; const int N = 300; int n; int l; int sx, sy; int ex, ey; int hash[300][300]; int mx[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; int my[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; void BFS() { int x, y; P p; while(!q.empty()) { p = q.front(); q.pop(); if(p.x == ex && p.y == ey) { cout << p.d << endl; return; } for(int i = 0; i < 8; i++) { x = p.x + mx[i]; y = p.y + my[i]; if( x < 0 || y < 0 || x >= l || y >= l) { continue; } if(!hash[x][y]) { hash[x][y] = 1; q.push(P(x, y, p.d + 1)); } } } } int main() { cin >> n; for(int i = 0; i < n; i++) { cin >> l; cin >> sx >> sy; cin >> ex >> ey; for(int j = 0; j < l; j++) { for(int k = 0; k < l; k++) { hash[j][k] = 0; } } while(!q.empty()) { q.pop(); } q.push(P(sx, sy, 0)); BFS(); } }