/* TU Darmstadt Programming Contest 2001
 * Problem: Knights
 * Author : Christoph Mueller
 * Comment: contains two solutions:
 *          - an easily programmed exhaustive search with complexity n^2
 *          - a formula that works in constant time, but was hard to find
 */
import java.io.*;
import java.util.*;

// the name says it all... 

class point {
    int x, y;

    public point(int p1, int p2) {
	x = p1;
	y = p2;
    }
}

public class knights {
  
    protected static BufferedReader in = 
	new BufferedReader(new InputStreamReader(System.in));

    public static void main( String args[ ] ) throws IOException
    {
	// read number of scenarios 

	int scen = Integer.parseInt(in.readLine());

	// for every scenario...

	while(scen-- > 0) {

	    // read size of the board

	    int l = Integer.parseInt(in.readLine());
	    
	    // read start and destination position */

	    point pos[] = new point[2];
	    for(int i=0; i<2; i++) {
		StringTokenizer st = new StringTokenizer(in.readLine(), 
							 " ", false);
		pos[i] = new point(Integer.parseInt(st.nextToken()),
				   Integer.parseInt(st.nextToken()));
	    }

	    // initialize result
	    
	    int result = l*l;

	    // ----------------------------------------------------------------
	    // slow solution: exhaustive search
	    // ----------------------------------------------------------------

	    if(false) {

		// a queue with the new positions */

		Vector v = new Vector(100,100);

		// for every position the number of moves necessary to get 
		// there; initialized with -1

		int field[][] = new int[l][l];
		for(int i=0; i<l; i++)
		    for(int j=0; j<l; j++)
			field[i][j] = -1;

		// put start position into queue and a zero into "field"

		v.addElement(pos[0]);
		field[pos[0].x][pos[0].y] = 0;

		// while there are new positions...

		while(!v.isEmpty()) {

		    // current position

		    point p = (point) v.elementAt(0);
		    v.removeElementAt(0);

		    // check if destination is reached

		    if(p.x == pos[1].x && p.y == pos[1].y) {
			result = field[p.x][p.y];
			break;
		    }

		    /* check all possible moves from current position */

		    for(int i=-1; i<=1; i+=2)
			for(int j=-2; j<=2; j+=4) 
			    for(int k=0; k<2; k++) {
			       
				// calculate new position

				point np = new point(p.x + (k==0 ? i : j),
						     p.y + (k==0 ? j : i));

				// if on board and not yet reached, store
				// number of moves and put into queue

				if(check(np,l) && field[np.x][np.y] < 0) {
				    field[np.x][np.y] = field[p.x][p.y] + 1;
				    v.addElement(np);
				}
			    }
		}
	    }

	    // ----------------------------------------------------------------
	    // fast solution: formula
	    // ----------------------------------------------------------------

	    else result = formula(pos[0], pos[1], l);
	    
	    // print result

	    System.out.println(result);
	}
    }

    // check if point is on board of size l*l

    static boolean check(point p, int l) {
	return 0 <= p.x && 0 <= p.y && p.x < l && p.y < l;
    }

    // calculate number of moves form p to q on board of size l*l

    static int formula(point p, point q, int l) {
	
	// calculate absolute difference of coordinates with dx < dy 
	
	int dx = Math.abs(p.x - q.x);
	int dy = Math.abs(p.y - q.y);
	if(dy < dx) { int buffer=dx; dx=dy; dy=buffer; }
	
	// distance is zero if points are identical 
	
	if(dx == 0 && dy == 0) return 0;
	
	// count corners for special situations
	
	int corners = 0;
	if((p.x == 0 || p.x == l-1) && (p.y == 0 || p.y == l-1)) 
	    corners++;
	if((q.x == 0 || q.x == l-1) && (q.y == 0 || q.y == l-1)) 
	    corners++;
	
	// special case l=4 and adjacient corners 
	
	if(corners == 2 && l==4 && (dx == 0 || dy == 0)) return 5;
	
	// other cases where the formula fails
	
	if(dy == 1 && dx == 1) return corners == 0 ? 2 : 4;
	if(dy == 1) return 3;
	if(dx == 2 && dy == 2) return 4;
	
	// formula: hard to explain without a picture...
	
	if(dx <= dy/2) {
	    if((dx+dy)%2 == 0) return 2*((dy+3)/4);
	    else return 2*((dy+1)/4)+1;
	}
	else {
	    if((dx+dy)%2 == 0) return 2*((dx+dy+4)/6);
	    else return 2*((dx+dy+1)/6)+1;
	}
    }

}














