namespace AtCoder; #nullable enable using System.Numerics; using G = Geometry2D, RationalComplex>; readonly record struct RationalComplex(Rational X, Rational Y) : IComplexWrapper> { public static implicit operator RationalComplex((Rational, Rational) value) => new(value.Item1, value.Item2); public static implicit operator (Rational, Rational)(RationalComplex self) => (self.X, self.Y); public static RationalComplex Factory(Rational x, Rational y) => new(x, y); public static Rational SqrtValue(Rational value) => throw new NotImplementedException(); public static int Sign(Rational value) => value.CompareTo(0); } interface IComplexWrapper where TSelf : IComplexWrapper { TElement X { get; } TElement Y { get; } static abstract TSelf Factory(TElement x, TElement y); static abstract TElement SqrtValue(TElement value); static abstract int Sign(TElement value); } static partial class Geometry2D where T : IComparable, IEqualityOperators, IComparisonOperators, IAdditionOperators, ISubtractionOperators, IMultiplyOperators, IDivisionOperators, IAdditiveIdentity, IMultiplicativeIdentity where C : struct, IComplexWrapper { public static T DotProduct(C l, C r) => l.X * r.X + l.Y * r.Y; public static T CrossProduct(C l, C r) => l.X * r.Y - l.Y * r.X; public static T Magnitude2(C e) => e.X * e.X + e.Y * e.Y; public static T Magnitude(C e) => C.SqrtValue(Magnitude2(e)); public static C Add(C l, C r) => C.Factory(l.X + r.X, l.Y + r.Y); public static C Sub(C l, C r) => C.Factory(l.X - r.X, l.Y - r.Y); public static C Mul(C l, C r) => C.Factory(l.X * r.X - l.Y * r.Y, l.X * r.Y + l.Y * r.X); public static C MulConst(C e, T k) => C.Factory(e.X * k, e.Y * k); public static C DivConst(C e, T k) => C.Factory(e.X / k, e.Y / k); public static bool Equal(C l, C r) => l.X == r.X && l.Y == r.Y; public static C Unit(C e) => DivConst(e, Magnitude(e)); public record struct DirectedSegment(C Ab, C Ad, bool Ends) { public readonly C Vector => Sub(Ad, Ab); } public static int CounterClockwise(DirectedSegment ds, C target) { var v = Sub(target, ds.Ab); var crossProduct = C.Sign(CrossProduct(ds.Vector, v)); if (crossProduct == 0) { if (!ds.Ends) return 0; if (C.Sign(DotProduct(ds.Vector, v)) < 0) return -1; // other side if (C.Sign(DotProduct(v, v) - DotProduct(ds.Vector, ds.Vector)) > 0) return 1; return 0; // on the segment } return crossProduct > 0 ? 2 : -2; } public static C? Intersection(DirectedSegment ds1, DirectedSegment ds2) { var (v1, v2, v3) = (ds1.Vector, ds2.Vector, Sub(ds2.Ab, ds1.Ab)); var k = CrossProduct(v1, v2); if (k == T.AdditiveIdentity) return null; var s = CrossProduct(v3, v2) / k; var t = CrossProduct(v3, v1) / k; if ( (ds1.Ends && (s < T.AdditiveIdentity || T.MultiplicativeIdentity < s)) || (ds2.Ends && (t < T.AdditiveIdentity || T.MultiplicativeIdentity < t)) ) return null; return Add(ds1.Ab, MulConst(v1, s)); } public static DirectedSegment Projection(C point, DirectedSegment line) { var (o, v) = (line.Ab, line.Vector); var end = Add(o, MulConst(v, DotProduct(v, Sub(point, o)) / Magnitude2(v))); return new(point, end, true); } public static List SortByArgument(IEnumerable points, C origin) { bool Upper(C v) => v.Y > origin.Y || v.Y == origin.Y && v.X > origin.X; var uppers = points.Where(Upper).ToList(); var lowers = points.Where(p => !Equal(p, origin) && !Upper(p)).ToList(); int Comparer(C p1, C p2) { if (Equal(p1, p2)) return 0; return CounterClockwise(new DirectedSegment(origin, p1, true), p2) > 0 ? -1 : 1; } var res = points.Where(p => Equal(p, origin)).ToList(); uppers.Sort(Comparer); lowers.Sort(Comparer); res.AddRange(uppers); res.AddRange(lowers); return res; } } static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } readonly record struct Rational : IAdditiveIdentity, Rational>, IAdditionOperators, Rational, Rational>, ISubtractionOperators, Rational, Rational>, IUnaryNegationOperators, Rational>, IMultiplicativeIdentity, Rational>, IMultiplyOperators, Rational, Rational>, IDivisionOperators, Rational, Rational>, IComparable>, IEqualityOperators, Rational, bool>, IComparisonOperators, Rational, bool> where T : IBinaryInteger, IConvertible { public T P { get; private init; } public T Q { get; private init; } public Rational(T p, T q) { if (q == T.Zero) throw new DivideByZeroException(); if (q < T.Zero) (p, q) = (-p, -q); var (x, y) = (T.Abs(p), q); while (y > T.Zero) (x, y) = (y, x % y); (P, Q) = (p / x, q / x); } public Rational(T p) { (P, Q) = (p, T.One); } public static Rational AdditiveIdentity => new(T.Zero); public static Rational MultiplicativeIdentity => new(T.One); public static implicit operator Rational(T i) => new(i); public static Rational operator -(Rational r) => new(-r.P, r.Q); public static Rational operator +(Rational r1, Rational r2) => new(r1.P * r2.Q + r1.Q * r2.P, r1.Q * r2.Q); public static Rational operator -(Rational r1, Rational r2) => new(r1.P * r2.Q - r1.Q * r2.P, r1.Q * r2.Q); public static Rational operator *(Rational r1, Rational r2) => new(r1.P * r2.P, r1.Q * r2.Q); public static Rational operator /(Rational r1, Rational r2) => new(r1.P * r2.Q, r1.Q * r2.P); public static bool operator <(Rational r1, Rational r2) => r1.CompareTo(r2) < 0; public static bool operator <=(Rational r1, Rational r2) => r1.CompareTo(r2) <= 0; public static bool operator >(Rational r1, Rational r2) => r1.CompareTo(r2) > 0; public static bool operator >=(Rational r1, Rational r2) => r1.CompareTo(r2) >= 0; public int CompareTo(Rational r) => (P * r.Q).CompareTo(Q * r.P); public override string ToString() => Q == T.One ? P.ToString()! : (P.ToDouble(null) / Q.ToDouble(null)).ToString(); } class AtCoder { object? Solve() { var t = Int(); var ans = new string[t]; for (var i = 0; i < t; i++) { ans[i] = Solve2() ? "Yes" : "No"; } Out(ans); return null; } bool Solve2() { var p1 = new RationalComplex(Int(), Int()); var p2 = new RationalComplex(Int(), Int()); var q1 = new RationalComplex(Int(), Int()); var q2 = new RationalComplex(Int(), Int()); if (p1 == q1 && p2 == q2) return true; var vp = G.Sub(p1, p2); var vq = G.Sub(q1, q2); if (G.Magnitude2(vp) <= G.Magnitude2(vq)) return false; if (vp.X * vq.Y != vp.Y * vq.X) return false; if (G.CounterClockwise(new G.DirectedSegment((0, 0), vp, true), vq) < 0) return false; return true; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; #pragma warning disable IDE0051 string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0); return input[iter++]; } T Input() where T : IParsable => T.Parse(String(), null); int Int() => Input(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } #pragma warning restore IDE0051 }