extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter, Binary};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0{
        a
    }else {
        gcd(b, a % b)
    }
}
#[derive(Copy, Clone, Eq, PartialEq)]
struct Position {
    x: i64, y: i64
}
impl Position {
    fn directions(&self) -> Vec<Line> {
        vec![
            Line{a: -1, b: 0, c: self.x},
            Line{a: 0, b: -1, c: self.y},
            Line{a: -1, b: -1, c: self.x + self.y},
            Line{a: -1, b: 1, c: self.x - self.y}
        ]
    }
}
#[derive(Copy, Clone, Eq, PartialEq)]
struct Line {
    a: i64, b: i64, c: i64
}
impl Line {
    fn cross_position(&self, other: &Self) -> Option<Position> {
        if self.is_parallel(other) {
            None
        }else {
            let d = self.a * other.b - self.b * other.a;
            let x = self.b * other.c - self.c * other.b;
            let y = self.c * other.a - self.a * other.c;
            if x % d == 0 && y % d == 0{
                Some(Position{x: x / d, y: y / d})
            }else {
                None
            }
        }
    }
    fn is_on_line(&self, point: &Position) -> bool {
        self.a * point.x + self.b * point.y + self.c == 0
    }
    fn is_parallel(&self, other: &Self) -> bool {
        self.a * other.b == self.b * other.a
    }
}
impl Display for Position {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        write!(f, "Position(x: {}, y: {})", self.x, self.y)
    }
}
fn solve(base_a: Position, base_b: Position, target: Position) -> usize {
    if base_a == target || base_b == target {
        return 0
    }
    let a_line = base_a.directions();
    let b_line = base_b.directions();
    if a_line.iter().any(|line|line.is_on_line(&target)) && b_line.iter().any(|line|line.is_on_line(&target)) {
        1
    }else{
        let current = if a_line.iter().any(|line| line.is_on_line(&target)) || b_line.iter().any(|line|line.is_on_line(&target)) {2} else {3};
        if a_line.iter().any(|line| b_line.contains(line)) {
            return current
        }
        for a in &a_line {
            for b in &b_line {
                if let Some(p) = a.cross_position(b) {
                    //println!("{}", p);
                    if p.directions().iter().any(|line| line.is_on_line(&target)) {
                        return current;
                    }
                }
            }
        }
        return current + 1;
    }
}
fn main() {
    let_all!(n: usize);
    for _ in 0 .. n {
        let_all!(ax: i64, ay: i64, bx: i64, by: i64, tx: i64, ty: i64);
        println!("{}", solve(Position{x: ax, y: ay}, Position{x: bx, y: by}, Position{x: tx, y: ty}));
    }
}


Measured memory_bytes: 5044