There are three cells on an infinite 2-dimensional grid, labeled $$$A$$$, $$$B$$$, and $$$F$$$. Find the length of the shortest path from $$$A$$$ to $$$B$$$ if:   in one move you can go to any of the four adjacent cells sharing a side;  visiting the cell $$$F$$$ is forbidden (it is an obstacle).

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Before each test case, there is an empty line. Each test case contains three lines. The first one contains two integers $$$x_A, y_A$$$ ($$$1 \le x_A, y_A \le 1000$$$) — coordinates of the start cell $$$A$$$. The second one contains two integers $$$x_B, y_B$$$ ($$$1 \le x_B, y_B \le 1000$$$) — coordinates of the finish cell $$$B$$$. The third one contains two integers $$$x_F, y_F$$$ ($$$1 \le x_F, y_F \le 1000$$$) — coordinates of the forbidden cell $$$F$$$. All cells are distinct. Coordinate $$$x$$$ corresponds to the column number and coordinate $$$y$$$ corresponds to the row number (see the pictures below).

Output $$$t$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th test case: the length of the shortest path from the cell $$$A$$$ to the cell $$$B$$$ if the cell $$$F$$$ is not allowed to be visited.

Note    An example of a possible shortest path for the first test case.     An example of a possible shortest path for the second test case.

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    let blank;
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    blank = input[z++];

    while(testCases--){
        let [xA, yA] = input[z++].split(' ').map(x=>Number(x));
        let [xB, yB] = input[z++].split(' ').map(x=>Number(x));
        let [xF, yF] = input[z++].split(' ').map(x=>Number(x));
        blank = input[z++];

        let distance = Math.abs(xA-xB) +Math.abs(yA-yB);

        if((xA === xB) && (xB === xF)){
            if((yA < yF && yF < yB) || (yB < yF && yF < yA)){
                distance += 2;
            }
        }
        if((yA === yB) && (yB === yF)){
            if((xA < xF && xF < xB) || (xB < xF && xF < xA)){
                distance += 2;
            }
        }
        console.log(distance);
    }
}

// process.stdin.resume();

process.stdin.setEncoding('utf8');

let input = '';
let currentLine = 0;

process.stdin.on('data', data => {
  input += data;
});

process.stdin.on('end', () => {
  input = input.trim().split('\n').map(str => str.trim());
  main();
});

function readLine() {
  return input[currentLine++];
}

function main() {
  let testCases = readLine();
  testCases = parseInt(testCases, 10);
  while (testCases--) {
    readLine();
    let start = readLine();
    let end = readLine();
    let wall = readLine();
    solve(start, end, wall);
  }
}

function solve(start, end, wall) {
  const [startX, startY] = start.split(' ').map((item) => parseInt(item, 10));
  const [endX, endY] = end.split(' ').map((item) => parseInt(item, 10));
  const [wallX, wallY] = wall.split(' ').map((item) => parseInt(item, 10));

  const p1 = Math.abs(startX - endX);
  const p2 = Math.abs(startY - endY);
  let res = p1 + p2;

  const isXEqual = startX === wallX && endX === wallX;
  const isXinRange = Math.max(startX, endX) > wallX && Math.min(startX, endX) < wallX;
  const isYEqual = startY === wallY && endY === wallY;
  const isYInRange = Math.max(startY, endY) > wallY && Math.min(startY, endY) < wallY;
  if (isXEqual && isYInRange || isYEqual && isXinRange) {
    res += 2;
  }
  console.log(res);
}

class CPIO {
  constructor() {
    const input = require("fs").readFileSync(process.stdin.fd);
    this.data = input.toString().split(/\s+/);
    this.pos = 0;
  }

  word() {
    return this.data[this.pos++];
  }

  int() {
    return Number(this.word());
  }

  ints(len) {
    const res = [];
    for (let i = 0; i < len; ++i) {
      res.push(this.int());
    }
    return res;
  }
};

const io = new CPIO;

let t = io.int();

while (t--) {
  const [xa, ya, xb, yb, xf, yf] = io.ints(6);
  let ans = Math.abs(xa - xb) + Math.abs(ya - yb);
  if ((xa === xb && xa === xf && yf > Math.min(ya, yb) && yf < Math.max(ya, yb))) ans += 2;
  else if (ya === yb && ya === yf && xf > Math.min(xa, xb) && xf < Math.max(xa, xb)) ans += 2;
  console.log(ans);
}

var v = 'abcdefghijklmnopqrstuvwxyz';
v = v.split('');
var findnum = function(n){
    for(l = 0; l < 26; l++){
        if(v[l] == n){
            return l + 1;
        }
    }
};
let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	var e = 0;
	var a0 = 0; var a1 = 0; var a2 = 0; var a3 = 0; var a4 = 0; var a5 = 0;
	for(i = 1; i <= t * 4; i++){
	    var a = lines[i].split(' ').map(Number);
        if(i % 4 === 1){
            continue;
        }else if(i % 4 == 2){
            a0 = a[0];
            a1 = a[1];
        }else if(i % 4 == 3){
            a2 = a[0];
            a3 = a[1];
        }else{
            a4 = a[0];
            a5 = a[1];
            var ans = Math.abs(a2 - a0) + Math.abs(a1 - a3);
            if(a0 == a2 && a0 == a4){
                if(a5 > a1 && a5 < a3 || a5 < a1 && a5 > a3){
                    ans += 2;
                }
            }else if(a1 == a3 && a1 == a5){
                if(a4 > a0 && a4 < a2 || a4 < a0 && a4 > a2){
                    ans += 2;
                }
            }
            console.log(ans);
        }
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    readLine();
    const a = readLine().split(" ").map(i => parseInt(i) - 1);
    const b = readLine().split(" ").map(i => parseInt(i) - 1);
    const f = readLine().split(" ").map(i => parseInt(i) - 1);
    let ans = Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]);
    if ((a[0] == b[0] && a[0] == f[0] && Math.min(a[1], b[1]) < f[1] && f[1] < Math.max(a[1], b[1]))
        || (a[1] == b[1] && a[1] == f[1] && Math.min(a[0], b[0]) < f[0] && f[0] < Math.max(a[0], b[0])))
    ans += 2;
    return ans;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

function gcd(x, y) {
   if (isZero(y)) {
      return x;
   }
   return gcd(y, x % y);
}

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function dist(xa, ya, xb, yb) {
   return Math.abs(xa - xb) + Math.abs(ya - yb);
}

function solve() {
   read();
   const [xa, ya] = readArray(Number);
   const [xb, yb] = readArray(Number);
   const [xf, yf] = readArray(Number);

   let ans = dist(xa, ya, xb, yb);
   if (xa === xb && xa === xf && (ya - yf) * (yb - yf) < 0 || ya === yb && ya === yf && (xa - xf) * (xb - xf) < 0) {
      ans += 2;
   }
   write(ans);
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function getCoOrdinate() {
	var aString = readLine();
    //console.log(aString);
    var aCorString = aString.split(' ');
    //console.log(aCorString);
    var aCorInt = [0, 0];
    aCorInt[0] = parseInt(aCorString[0]);
    aCorInt[1] = parseInt(aCorString[1]);

	return aCorInt;
}

function difference(a, b) {
  return Math.abs(a - b);
}

function main()
{
    var testCases = parseInt(readLine());

    //console.log(testCases);

    for(let i = 0; i < testCases; i++)
    {
    	var dummyInput = readLine();
    	var corA = getCoOrdinate();
    	var corB = getCoOrdinate();
    	var corF = getCoOrdinate();

    	let diff = difference(corA[0], corB[0]) + difference(corA[1], corB[1]);

    	if(corA[0] == corB[0] && corA[0] == corF[0] && ((corF[1] < corA[1] && corF[1] > corB[1]) || (corF[1] > corA[1] && corF[1] < corB[1]))) {
    		diff = diff + 2;
    	}

    	if(corA[1] == corB[1] && corA[1] == corF[1] && ((corF[0] < corA[0] && corF[0] > corB[0]) || (corF[0] > corA[0] && corF[0] < corB[0]))) {
    		diff = diff + 2;
    	}

    	console.log(diff);

    	//break;
    }

}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
       // let p1x,p1y,p2x,p2y,p3x,p3y;

        readLine();
        p1=readLine();
        p2=readLine();
        p3=readLine();
        p1=p1.split(" ");
        p2=p2.split(" ");
        p3=p3.split(" ");
        p1x=parseInt(p1[0]);
        p1y=parseInt(p1[1]);
        p2x=parseInt(p2[0]);
        p2y=parseInt(p2[1]);
        p3x=parseInt(p3[0]);
        p3y=parseInt(p3[1]);

        let val=Math.abs(p1x-p2x);
        val+=Math.abs(p1y-p2y);
        if(p1x===p2x && p2x===p3x)
        {
            if((p1y<p3y && p3y<p2y)||(p2y<p3y && p3y<p1y))
            {
                //cout<<p1y<<" "<<p3y<<" "
                val+=2;
            }
        }
        if(p1y===p2y && p2y===p3y)
        {
            if((p1x<p3x && p3x<p2x)||(p2x<p3x && p3x<p1x))
                val+=2;
        }
        //cout<<val<<endl;
        console.log(val);

    }
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var t = +lines[l++]
    for (var i = 0; i < t; i++) {
        l++
        var a = lines[l++].trim().split(' ').map(Number)
        var b = lines[l++].trim().split(' ').map(Number)
        var f = lines[l++].trim().split(' ').map(Number)
        console.log(solve(a, b, f))
    }
});

function solve(a, b, f) {
    if (a[0] === b[0] && a[0] === f[0]) {
        if (a[1] < f[1] && f[1] < b[1] || a[1] > f[1] && f[1] > b[1])
            return 2 + Math.abs(a[1] - b[1])
    }
    if (a[1] === b[1] && a[1] === f[1]) {
        if (a[0] < f[0] && f[0] < b[0] || a[0] > f[0] && f[0] > b[0])
            return 2 + Math.abs(a[0] - b[0])
    }

    return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1])
}

let input = '';
process.stdin.on('data', (str) => input += str);
process.stdin.on('end', () => {
    const [n, ...lines] = input.trim().split('\n')
        .map(l => l.trim());

    for (let i=1; i<lines.length; i+=1) {
        const a = lines[i].split(' ').map((id) => id - '0');
        i += 1;
        const b = lines[i].split(' ').map((id) => id - '0');
        i += 1;
        const p = lines[i].split(' ').map((id) => id - '0')
        i+= 1;
        console.log(solve(a,b,p))
    }
});

const solve = (a, b, p) =>{
    try{
        const x1 = a[0]; const y1 = a[1];
        const x2 = b[0]; const y2 = b[1];
        const x3 = p[0]; const y3 = p[1];

        if((x1=== x2) && (x2=== x3)){
            if((y2 < y3 && y3 < y1) || (y1 < y3 && y3 < y2)){
                return Math.abs(y2 - y1) + 2
            } else{
                return Math.abs(y2 - y1);
            }
        }else if((y1 === y2) && (y2 === y3)){
            if((x2 < x3 && x3 < x1) || (x1 < x3 && x3 < x2)){
                return Math.abs(x2 - x1) + 2;
            }else{
                return Math.abs(x2 - x1);
            }
        }else{
            return Math.abs(x2-x1) + Math.abs(y2-y1);
        }
    }catch (ex){
        console.log('ex:', ex)
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var s = next();
		var Ax = nextInt();
		var Ay = nextInt();
		var Bx = nextInt();
		var By = nextInt();
		var Fx = nextInt();
		var Fy = nextInt();
		var output = Math.abs(Ax - Bx) + Math.abs(Ay - By);
		if(Ax == Fx && Ax == Bx && Math.min(Ay, By) <= Fy && Fy <= Math.max(Ay, By)){
			output += 2;
		}else if(Ay == Fy && Ay == By && Math.min(Ax, Bx) <= Fx && Fx <= Math.max(Ax, Bx)){
			output += 2;
		}

		myout(output);
	}
}

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.
const INT = Math.floor;
Array.prototype.last = function () {
    return this.length === 0 ? undefined : this[this.length - 1];
};
Array.prototype.isEmpty = function () {
    return this.length === 0;
};
const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);
const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);
const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
const bigIntAbs = (arg) => (arg < 0 ? -arg : arg);
function read_stdin() {
    return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');
}
class Input {
    constructor(str) {
        this.index = 0;
        this.inputs = (str ? str : read_stdin()).split(/\s+/);
    }
    number() {
        return Number(this.inputs[this.index++]);
    }
    numbers(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(Number);
    }
    bigint() {
        return BigInt(this.inputs[this.index++]);
    }
    bigints(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(BigInt);
    }
    word() {
        return this.inputs[this.index++];
    }
    words(n) {
        return this.inputs.slice(this.index, (this.index += n));
    }
}
function array(len, init) {
    return Array(len).fill(init);
}
function array2(h, w, init) {
    return array(h, 0).map(() => array(w, init));
}
function main() {
    const input = new Input();
    const t = input.number();
    const ans = Array(t);
    for (let i = 0; i < t; i++) {
        let xa = input.number();
        let ya = input.number();
        let xb = input.number();
        let yb = input.number();
        const xf = input.number();
        const yf = input.number();
        if (xa === xb) {
            ;
            [ya, yb] = [ya, yb].sort((a, b) => a - b);
            if (xf === xa && ya < yf && yf < yb) {
                ans[i] = Math.abs(yb - ya) + 2;
            }
            else {
                ans[i] = Math.abs(yb - ya);
            }
        }
        else if (ya === yb) {
            ;
            [xa, xb] = [xa, xb].sort((a, b) => a - b);
            if (yf === ya && xa < xf && xf < xb) {
                ans[i] = Math.abs(xb - xa) + 2;
            }
            else {
                ans[i] = Math.abs(xb - xa);
            }
        }
        else {
            ans[i] = Math.abs(xb - xa) + Math.abs(yb - ya);
        }
    }
    console.log(ans.join('\n'));
}
main();
//# sourceMappingURL=aoj.js.map

//function main(input) {
function main() {
  var getDistance = function( sa, sb, sf ) {
    //console.log("solve is called");
    //console.log(sa);
    //console.log(sb);
    //console.log(sf);
    //print(")"+sa);
    //print(")"+sb);
    //print(")"+sf);

    a = sa.split(" ").map(function(n){return parseInt(n,10);});
    b = sb.split(" ").map(function(n){return parseInt(n,10);});
    f = sf.split(" ").map(function(n){return parseInt(n,10);});
    //console.log(a);
    //console.log(b);
    //console.log(f);

    dist = Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]);
    if (a[0]===b[0] && a[0]===f[0]) {
      if ((a[1]<f[1]&&f[1]<b[1])||
          (b[1]<f[1]&&f[1]<a[1])) {
        dist+=2;
      }
    } else if (a[1]===b[1] && a[1]===f[1]) {
      if ((a[0]<f[0]&&f[0]<b[0])||
          (b[0]<f[0]&&f[0]<a[0])) {
        dist+=2;
      }
    }
    //console.log(dist);
    return dist;
  }

  //lines = input.split("\n");
  //cntTestcase = parseInt(lines[0],10);
  cntTestcase = parseInt(readline(),10);
  readline();
  for (var i=0; i<cntTestcase; i++) {
    //lineNum = 2+i*4;
    //getDistance(
    //  lines[lineNum],
    //  lines[lineNum+1],
    //  lines[lineNum+2]);
    dist = getDistance(
      readline(),
      readline(),
      readline());
    readline();
    print(dist);
  }
}

//main(require("fs").readFileSync("/dev/stdin", "utf8"));
main();

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    let blank;
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    blank = input[z++];

    while(testCases--){
        let [xA, yA] = input[z++].split(' ').map(x=>Number(x));
        let [xB, yB] = input[z++].split(' ').map(x=>Number(x));
        let [xF, yF] = input[z++].split(' ').map(x=>Number(x));
        blank = input[z++];

        let distance = 0;

        while((xA !== xB) || (yA !== yB)){
            if(xA < xB){
                if((xA+1) == xF&& yA === yF) yA++;
                else xA++;
                distance++;
            }
            else if(xA > xB){
                if((xB+1) == xF && yB === yF) yB++;
                else xB++
                distance++;
            }
            if(yA < yB){
                if((yA+1) == yF&& xA === xF) xA++;
                else yA++;
                distance++;
            }
            else if(yA > yB){
                if((yB+1) == yF && xB === xF) xB++;
                else yB++;
                distance++;
            }
            // console.log(xA,yA);
            // console.log(xB,yB);
        }
        console.log(distance);
    }
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    let blank;
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    blank = input[z++];

    while(testCases--){
        let [xA, yA] = input[z++].split(' ').map(x=>Number(x));
        let [xB, yB] = input[z++].split(' ').map(x=>Number(x));
        let [xF, yF] = input[z++].split(' ').map(x=>Number(x));
        blank = input[z++];

        let distance = 0;

        while((xA !== xB) || (yA !== yB)){
            if((xA !== xB) && (yA !== yB)){
                if(xA < xB){ distance++;
                    xA++;
                }
                else{distance++;
                    xB++;
                }
                if(yA < yB){ distance++;
                    yA++;
                }
                else{ distance++;
                    yB++;
                }
            }
            else if((xA === xB) && (yA !== yB)){
                if(yA < yB){
                    if(( yA + 1 ) === yF) distance+= 2;
                    yA++;
                }
                else{
                    if(( yB + 1 ) === yF) distance+= 2;
                    yB++;
                }
                distance++;
            }
            else if((xA !== xB) && (yA === yB)){
                if(xA < xB){
                    if(( xA + 1 ) === xF) distance+=2;
                    xA++;
                }
                else{
                    if(( xB + 1 ) === xF) distance+=2;
                    xB++;
                }
                distance++;
            }
        }
        console.log(distance);
    }
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    let blank;
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    blank = input[z++];

    while(testCases--){
        let [xA, yA] = input[z++].split(' ').map(x=>Number(x));
        let [xB, yB] = input[z++].split(' ').map(x=>Number(x));
        let [xF, yF] = input[z++].split(' ').map(x=>Number(x));
        blank = input[z++];

        let distance = 0;

        while((xA !== xB) || (yA !== yB)){
            if((xA !== xB) && (yA !== yB)){
                if(xA < xB){
                    // if(( xA + 1 ) === xF) distance++;
                    xA++;
                }
                else{
                    // if(( xB + 1 ) === xF) distance++;
                    xB++;
                }
                if(yA < yB){
                    // if(( yA + 1 ) === yF) distance++;
                    yA++;
                }
                else{
                    // if(( yB + 1 ) === yF) distance++;
                    yB++;
                }
                distance+=2;
            }
            else if((xA === xB) && (yA !== yB)){
                if(yA < yB){
                    if(( yA + 1 ) === yF) distance+= 2;
                    yA++;
                }
                else{
                    if(( yB + 1 ) === yF) distance+= 2;
                    yB++;
                }
                distance++;
            }
            else if((xA !== xB) && (yA === yB)){
                if(xA < xB){
                    if(( xA + 1 ) === xF) distance+=2;
                    xA++;
                }
                else{
                    if(( xB + 1 ) === xF) distance+=2;
                    xB++;
                }
                distance++;
            }
        }
        console.log(distance);
    }
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    let blank;
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    blank = input[z++];

    while(testCases--){
        let [xA, yA] = input[z++].split(' ').map(x=>Number(x));
        let [xB, yB] = input[z++].split(' ').map(x=>Number(x));
        let [xF, yF] = input[z++].split(' ').map(x=>Number(x));
        blank = input[z++];

        let distance = 0;

        while((xA !== xB) || (yA !== yB)){
            if((xA !== xB) && (yA !== yB)){
                if(xA < xB){
                    // if(( xA + 1 ) === xF) distance++;
                    xA++;
                }
                else{
                    // if(( xB + 1 ) === xF) distance++;
                    xB++;
                }
                if(yA < yB){
                    // if(( yA + 1 ) === yF) distance++;
                    yA++;
                }
                else{
                    // if(( yB + 1 ) === yF) distance++;
                    yB++;
                }
                distance++;
            }
            else if((xA === xB) && (yA !== yB)){
                if(yA < yB){
                    if(( yA + 1 ) === yF) distance+= 2;
                    yA++;
                }
                else{
                    if(( yB + 1 ) === yF) distance+= 2;
                    yB++;
                }
                distance++;
            }
            else if((xA !== xB) && (yA === yB)){
                if(xA < xB){
                    if(( xA + 1 ) === xF) distance+=2;
                    xA++;
                }
                else{
                    if(( xB + 1 ) === xF) distance+=2;
                    xB++;
                }
                distance++;
            }
        }
        console.log(distance);
    }
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    let blank;
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    blank = input[z++];

    while(testCases--){
        let [xA, yA] = input[z++].split(' ').map(x=>Number(x));
        let [xB, yB] = input[z++].split(' ').map(x=>Number(x));
        let [xF, yF] = input[z++].split(' ').map(x=>Number(x));
        blank = input[z++];

        let distance = 0;

        while((xA !== xB) || (yA !== yB)){
            if((xA !== xB) && (yA !== yB)){
                if(xA < xB){
                    if(( xA + 1 ) === xF) distance++;
                    xA++;
                }
                else{
                    if(( xB + 1 ) === xF) distance++;
                    xB++;
                }
                if(yA < yB){
                    if(( yA + 1 ) === yF) distance++;
                    yA++;
                }
                else{
                    if(( yB + 1 ) === yF) distance++;
                    yB++;
                }
                distance+=2;
            }
            else if((xA === xB) && (yA !== yB)){
                if(yA < yB){
                    if(( yA + 1 ) === yF) distance+= 2;
                    yA++;
                }
                else{
                    if(( yB + 1 ) === yF) distance+= 2;
                    yB++;
                }
                distance++;
            }
            else if((xA !== xB) && (yA === yB)){
                if(xA < xB){
                    if(( xA + 1 ) === xF) distance+=2;
                    xA++;
                }
                else{
                    if(( xB + 1 ) === xF) distance+=2;
                    xB++;
                }
                distance++;
            }
        }
        console.log(distance);
    }
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    let blank;
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    blank = input[z++];

    while(testCases--){
        let [xA, yA] = input[z++].split(' ').map(x=>Number(x));
        let [xB, yB] = input[z++].split(' ').map(x=>Number(x));
        let [xF, yF] = input[z++].split(' ').map(x=>Number(x));
        blank = input[z++];

        let distance = 0;

        while((xA !== xB) || (yA !== yB)){
            if((xA !== xB) && (yA !== yB)){
                if(xA < xB){
                    if(( xA + 1 ) === xF) distance++;
                    xA++;
                }
                else{
                    if(( xB + 1 ) === xF) distance++;
                    xB++;
                }
                if(yA < yB){
                    if(( yA + 1 ) === yF) distance++;
                    yA++;
                }
                else{
                    if(( yB + 1 ) === yF) distance++;
                    yB++;
                }
                distance++;
            }
            else if((xA === xB) && (yA !== yB)){
                if(yA < yB){
                    if(( yA + 1 ) === yF) distance+= 2;
                    yA++;
                }
                else{
                    if(( yB + 1 ) === yF) distance+= 2;
                    yB++;
                }
                distance++;
            }
            else if((xA !== xB) && (yA === yB)){
                if(xA < xB){
                    if(( xA + 1 ) === xF) distance+=2;
                    xA++;
                }
                else{
                    if(( xB + 1 ) === xF) distance+=2;
                    xB++;
                }
                distance++;
            }
        }
        console.log(distance);
    }
}

//function main(input) {
function main() {
  var getDistance = function( sa, sb, sf ) {
    //console.log("solve is called");
    //console.log(sa);
    //console.log(sb);
    //console.log(sf);
    print(")"+sa);
    print(")"+sb);
    print(")"+sf);

    a = sa.split(" ").map(function(n){return parseInt(n,10);});
    b = sb.split(" ").map(function(n){return parseInt(n,10);});
    f = sf.split(" ").map(function(n){return parseInt(n,10);});
    //console.log(a);
    //console.log(b);
    //console.log(f);

    dist = Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]);
    if (a[0]===b[0] && a[0]===f[0]) {
      if ((a[1]<f[1]&&f[1]<b[1])||
          (b[1]<f[1]&&f[1]<a[1])) {
        dist+=2;
      }
    } else if (a[1]===b[1] && a[1]===f[1]) {
      if ((a[0]<f[0]&&f[0]<b[0])||
          (b[0]<f[0]&&f[0]<a[0])) {
        dist+=2;
      }
    }
    //console.log(dist);
    return dist;
  }

  //lines = input.split("\n");
  //cntTestcase = parseInt(lines[0],10);
  cntTestcase = parseInt(readline(),10);
  readline();
  for (var i=0; i<cntTestcase; i++) {
    //lineNum = 2+i*4;
    //getDistance(
    //  lines[lineNum],
    //  lines[lineNum+1],
    //  lines[lineNum+2]);
    dist = getDistance(
      readline(),
      readline(),
      readline());
    readline();
    print(dist);
  }
}

//main(require("fs").readFileSync("/dev/stdin", "utf8"));
main();