#include #include #include using Real = boost::rational; struct Point { Point() {} Real x = 0, y = 0; }; bool operator==(Point lhs, Point rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } struct Line { Real m, c; bool valid = true; Line() {} Line(Point lhs, Point rhs) { if (lhs.x - rhs.x == 0) { valid = false; m = lhs.x; } else { m = (lhs.y - rhs.y) / (lhs.x - rhs.x); c = lhs.y - m * lhs.x; } } }; std::pair intersect(Line lhs, Line rhs) { if (!lhs.valid && !rhs.valid) return {false, Point()}; if (!lhs.valid) { Point p; p.x = lhs.m; p.y = rhs.m * p.x + rhs.c; return {true, p}; } else if (!rhs.valid) { Point p; p.x = rhs.m; p.y = lhs.m * p.x + lhs.c; return {true, p}; } if (lhs.m == rhs.m) return {false, Point()}; Point p; p.x = (lhs.c - rhs.c) / (rhs.m - lhs.m); p.y = lhs.m * p.x + lhs.c; return {true, p}; } Real dist(Point lhs, Point rhs) { return (lhs.x - rhs.x) * (lhs.x - rhs.x) + (lhs.y - rhs.y) * (lhs.y - rhs.y); } void solve() { std::vector points(4); for (int i = 0; i < 4; i++) { long long x, y; std::cin >> x >> y; points[i].x = x; points[i].y = y; } if (points[0] == points[2] || points[1] == points[3]) { std::cout << "Yes" << '\n'; return; } Line l1(points[0], points[2]); Line l2(points[1], points[3]); auto [f, c] = intersect(l1, l2); if (!f) { std::cout << "No" << '\n'; return; } Real d1 = dist(points[0], c); Real d2 = dist(points[1], c); Real D1 = dist(points[0], points[2]); Real D2 = dist(points[1], points[3]); Real k1 = D1 / d1; Real k2 = D2 / d2; if (k1 == k2 && 0 < k1 && k1 < 1) { std::cout << "Yes" << '\n'; } else { std::cout << "No" << '\n'; } } int main() { std::cin.tie(0)->sync_with_stdio(0); std::cout << std::fixed << std::setprecision(16); int t = 1; std::cin >> t; while (t--) solve(); }