for cas in xrange(input()): n, sx, sy, ex, ey, bx, by = map(int, raw_input().strip().split()) print abs(sx - ex) + abs(sy - ey) + 2 * ((sx == ex or sy == ey) and min(sx, ex) <= bx <= max(sx, ex) and min(sy, ey) <= by <= max(sy, ey) )