#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*, BufWriter, StdinLock, StdoutLock}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::>() }; } let t = input!(usize); for _ in 0..t { solve(&mut scan, &mut out); } } fn solve(scan: &mut Scanner, out: &mut BufWriter) { macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::>() }; } let (x1, y1, x2, y2, X1, Y1, X2, Y2) = ( input!(i128), input!(i128), input!(i128), input!(i128), input!(i128), input!(i128), input!(i128), input!(i128), ); // (x1, y1), (X1, Y1) を通る直線の方程式と (x2, y2), (X2, Y2) を通る直線の方程式を求める // (x1 < X1 < cx) or (cx < x1 < X1) みたいな位置関係でないなら一致できない? let is_parallel = { let a1 = Y1 - y1; let b1 = x1 - X1; let a2 = Y2 - y2; let b2 = x2 - X2; a1 * b2 - a2 * b1 == 0 }; if is_parallel { if (x1 < X1 && X1 < X2 && X2 < x2) || (x2 < X2 && X2 < X1 && X1 < x1) { if (y1 < Y1 && Y1 < Y2 && Y2 < y2) || (y2 < Y2 && Y2 < Y1 && Y1 < y1) { let a1 = Y1 - y1; let b1 = x1 - X1; let a2 = Y2 - y2; let b2 = x2 - X2; let c1 = X1 * y1 - x1 * Y1; let c2 = X2 * y2 - x2 * Y2; if a1 * b2 == a2 * b1 && a1 * c2 == a2 * c1 { writeln!(out, "Yes"); return; } } } writeln!(out, "No"); return; } else { let a1 = Y1 - y1; let b1 = x1 - X1; let a2 = Y2 - y2; let b2 = x2 - X2; let c1 = X1 * y1 - x1 * Y1; let c2 = X2 * y2 - x2 * Y2; let d = a1 * b2 - a2 * b1; let cx = (b1 * c2 - b2 * c1) as f64 / d as f64; let cy = (a2 * c1 - a1 * c2) as f64 / d as f64; // cx == X1 とか cy == Y1 とかだと一致できない if (b1 * c2 - b2 * c1) == X1 * d || (b1 * c2 - b2 * c1) == X2 * d { writeln!(out, "No"); return; } if (a2 * c1 - a1 * c2) == Y1 * d || (a2 * c1 - a1 * c2) == Y2 * d { writeln!(out, "No"); return; } let e1 = b1 * c2 - b2 * c1; let e2 = a2 * c1 - a1 * c2; if d > 0 { if (e1 < X1 * d && X1 < x1) || (x1 < X1 && X1 * d < e1) { if (e1 < X2 * d && X2 < x2) || (x2 < X2 && X2 * d < e1) { if (e2 < Y1 * d && Y1 < y1) || (y1 < Y1 && Y1 * d < e2) { if (e2 < Y2 * d && Y2 < y2) || (y2 < Y2 && Y2 * d < e2) { let dx11 = cx - x1 as f64; let dy11 = cy - y1 as f64; let dx12 = cx - X1 as f64; let dy12 = cy - Y1 as f64; let dx21 = cx - x2 as f64; let dy21 = cy - y2 as f64; let dx22 = cx - X2 as f64; let dy22 = cy - Y2 as f64; if ((dx11 * dx11 + dy11 * dy11) * (dx22 * dx22 + dy22 * dy22) - (dx12 * dx12 + dy12 * dy12) * (dx21 * dx21 + dy21 * dy21)) .abs() < 1e-6 { writeln!(out, "Yes"); return; } } } } } } else { if (e1 > X1 * d && X1 < x1) || (x1 < X1 && X1 * d > e1) { if (e1 > X2 * d && X2 < x2) || (x2 < X2 && X2 * d > e1) { if (e2 > Y1 * d && Y1 < y1) || (y1 < Y1 && Y1 * d > e2) { if (e2 > Y2 * d && Y2 < y2) || (y2 < Y2 && Y2 * d > e2) { let dx11 = cx - x1 as f64; let dy11 = cy - y1 as f64; let dx12 = cx - X1 as f64; let dy12 = cy - Y1 as f64; let dx21 = cx - x2 as f64; let dy21 = cy - y2 as f64; let dx22 = cx - X2 as f64; let dy22 = cy - Y2 as f64; if ((dx11 * dx11 + dy11 * dy11) * (dx22 * dx22 + dy22 * dy22) - (dx12 * dx12 + dy12 * dy12) * (dx21 * dx21 + dy21 * dy21)) .abs() < 1e-6 { writeln!(out, "Yes"); return; } } } } } } writeln!(out, "No"); } } struct Scanner { reader: R, buf_str: Vec, buf_iter: str::SplitWhitespace<'static>, } impl Scanner { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }