use std::f64::consts::PI;

const EPS: f64 = 1e-8;

fn main() {
    let mut sc = Scanner::new();

    let q = sc.next::<usize>();
    for _ in 0..q {
        let p0 = sc.next::<Pt>();
        let p1 = sc.next::<Pt>();
        let p2 = sc.next::<Pt>();
        let p3 = sc.next::<Pt>();

        let ans = if intersect_line_segment(&LineSegment(p0, p1), &LineSegment(p2, p3)) {
            1
        } else {
            0
        };

        println!("{}", ans);
    }
}

pub fn cross(a: Pt, b: Pt) -> f64 {
    (a.conj() * b).im
}

pub fn dot(a: Pt, b: Pt) -> f64 {
    (a.conj() * b).re
}

pub enum CCW {
    /// a->b->c is counter clockwise
    CounterClockwise = 1,
    /// a->b->c is counter clockwise
    Clockwise = -1,
    /// c--a--b
    OnLineBack = 2,
    /// a--b--c
    OnLineFront = -2,
    /// a--c--b
    OnSegment = 0,
}

pub fn ccw(a: Pt, b: Pt, c: Pt) -> CCW {
    let b = b - a;
    let c = c - a;
    if cross(b, c) > 0.0 {
        CCW::CounterClockwise
    } else if cross(b, c) < 0.0 {
        CCW::Clockwise
    } else if dot(b, c) < 0.0 {
        CCW::OnLineBack
    } else if b.norm() < c.norm() {
        CCW::OnLineFront
    } else {
        CCW::OnSegment
    }
}

/// Signed area of triangle
pub fn triangle_signed_area(a: Pt, b: Pt, c: Pt) -> f64 {
    cross(b - a, c - a) / 2.0
}

struct Line(Pt, Pt);
struct LineSegment(Pt, Pt);

enum CrossLine {
    Parallel,
    Cross(Pt),
}

enum CrossLineSegment {
    None,
    Many,
    One(Pt),
}

fn intersect_line(a: &Line, b: &Line) -> bool {
    cross(a.1 - a.0, b.1 - b.0) > EPS || cross(a.1 - a.0, b.0 - b.1) < EPS
}

fn intersect_line_segment(a: &LineSegment, b: &LineSegment) -> bool {
    ccw(a.0, a.1, b.0) as i32 * ccw(a.0, a.1, b.1) as i32 <= 0
        && ccw(b.0, b.1, a.0) as i32 * ccw(b.0, b.1, a.1) as i32 <= 0
}

// fn cross_line_segment(a: &LineSegment, b: &LineSegment) -> CrossLineSegment {
//     use CrossLineSegment::*;

//     // normalize a to [(0, 0), (0, 1)]
//     let b0 = b.0 - a.0;
//     let b1 = b.1 - a.0;
//     let va = a.1 - a.0;

//     let b0 = b0 / va;
//     let b1 = b1 / va;

//     if b0.im * b1.im > 0.0 {
//         return None;
//     }
//     if b0.re < 0.0 && b1.re < 0.0 || b0.re > 1.0 && b0.re > 1.0 {
//         return None;
//     }

//     if b0.re * none

//     todo!()
// }

//==========

use std::fmt::Debug;
use std::ops::{Add, Div, Mul, Sub};

#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug, Default)]
#[repr(C)]
pub struct Complex<T> {
    /// Real portion of the complex number
    pub re: T,
    /// Imaginary portion of the complex number
    pub im: T,
}

impl<T> Complex<T> {
    #[inline]
    pub fn new(re: T, im: T) -> Self {
        Complex { re, im }
    }
}

impl Complex<f64> {
    #[inline]
    pub fn conj(&self) -> Self {
        Self::new(self.re.clone(), -self.im.clone())
    }

    #[inline]
    pub fn norm(&self) -> f64 {
        self.re.hypot(self.im)
    }

    #[inline]
    pub fn arg(&self) -> f64 {
        self.im.atan2(self.re)
    }

    #[inline]
    pub fn abs(&self) -> f64 {
        self.im.atan2(self.re)
    }
}

impl<T: Add<Output = T>> Add for Complex<T> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self::Output {
        Self::new(self.re + rhs.re, self.im + rhs.im)
    }
}

impl<T: Sub<Output = T>> Sub for Complex<T> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self::Output {
        Self::new(self.re - rhs.re, self.im - rhs.im)
    }
}

impl<T: Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T>> Mul for Complex<T> {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self::Output {
        Self::new(
            self.re * rhs.re - self.im * rhs.im,
            self.re * rhs.im + self.im * rhs.re,
        )
    }
}

impl<T: Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>> Div
    for Complex<T>
{
    type Output = Self;
    fn div(self, rhs: Self) -> Self::Output {
        let d = rhs.re * rhs.re + rhs.im * rhs.im;
        Self::new(
            (self.re * rhs.re + self.im * rhs.im) / d,
            (self.im * rhs.re - self.re * rhs.im) / d,
        )
    }
}

type Pt = Complex<f64>;

//==========

pub struct Scanner {
    buf: Vec<char>,
    cur: usize,
}

impl Scanner {
    pub fn new() -> Scanner {
        Scanner {
            buf: vec![],
            cur: 0,
        }
    }

    fn fill(&mut self) {
        let mut s = String::new();
        let len = std::io::stdin().read_line(&mut s).unwrap();
        if len == 0 {
            panic!("unexpected EOF");
        }
        for c in s.chars() {
            self.buf.push(c);
        }
    }

    pub fn next_char(&mut self) -> char {
        'outer: loop {
            if self.cur >= self.buf.len() {
                self.fill();
            }
            while self.cur < self.buf.len() {
                if !self.buf[self.cur].is_whitespace() {
                    break 'outer;
                }
                self.cur += 1;
            }
        }
        let ret = self.buf[self.cur];
        self.cur += 1;
        ret
    }

    pub fn next_word(&mut self) -> String {
        'outer: loop {
            if self.cur >= self.buf.len() {
                self.fill();
            }
            while self.cur < self.buf.len() {
                if !self.buf[self.cur].is_whitespace() {
                    break 'outer;
                }
                self.cur += 1;
            }
        }

        let mut s = String::new();
        while self.cur < self.buf.len() && !self.buf[self.cur].is_whitespace() {
            s.push(self.buf[self.cur]);
            self.cur += 1;
        }
        s
    }

    pub fn next<T: Reader>(&mut self) -> T {
        T::read(self)
    }

    pub fn next_vec_len<T: Reader>(&mut self) -> Vec<T> {
        let n: usize = self.next();
        self.next_vec(n)
    }

    pub fn next_vec<T: Reader>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }
}

pub trait Reader {
    fn read(sc: &mut Scanner) -> Self;
}

impl<T: Reader> Reader for Complex<T> {
    fn read(sc: &mut Scanner) -> Self {
        Self::new(sc.next(), sc.next())
    }
}

impl Reader for char {
    fn read(sc: &mut Scanner) -> Self {
        sc.next_char()
    }
}

macro_rules! impl_for_from_str {
    ($typ:ty) => {
        impl Reader for $typ {
            fn read(sc: &mut Scanner) -> Self {
                sc.next_word().parse().unwrap()
            }
        }
    };
}

impl_for_from_str!(i8);
impl_for_from_str!(u8);
impl_for_from_str!(i16);
impl_for_from_str!(u16);
impl_for_from_str!(i32);
impl_for_from_str!(u32);
impl_for_from_str!(i64);
impl_for_from_str!(u64);
// impl_for_from_str!(i128);
// impl_for_from_str!(u128);
impl_for_from_str!(isize);
impl_for_from_str!(usize);
impl_for_from_str!(f32);
impl_for_from_str!(f64);
impl_for_from_str!(String);



Measured memory_bytes: 5136