/* -*- coding: utf-8 -*- * * 3437.cc: No.3437 [Cherry 8th Tune C] Silhouette - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MOD = 998244353; /* typedef */ using ll = long long; using tp3 = tuple; template struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; } MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; } explicit operator int() const { return v; } MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator-() const { return MI(MOD - v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; using mi = MI; template struct Pt { T x, y; Pt() {} Pt(T _x, T _y) : x(_x), y(_y) {} Pt(const Pt &p) : x(p.x), y(p.y) {} Pt operator+(const Pt p) const { return Pt(x + p.x, y + p.y); } Pt operator-() const { return Pt(-x, -y); } Pt operator-(const Pt p) const { return Pt(x - p.x, y - p.y); } Pt operator*(T t) const { return Pt(x * t, y * t); } Pt operator/(T t) const { return Pt(x / t, y / t); } T dot(Pt v) const { return x * v.x + y * v.y; } T cross(Pt v) const { return x * v.y - y * v.x; } T d2() { return x * x + y * y; } bool operator==(const Pt pt) const { return x == pt.x && y == pt.y; } }; using ptd = Pt; using ptmi = Pt; struct Rat { ll n, d; Rat(): n(), d(1) {} Rat(ll _n): n(_n), d(1) {} Rat(ll _n, ll _d): n(_n), d(_d) { reduce(); } void reduce() { if (d == 0) n = 0; else { if (d < 0) n = -n, d = -d; ll g = gcd(abs(n), d); n /= g, d /= g; } } explicit operator double() const { return (double)n / d; } explicit operator mi() const { return mi(n) * mi(d).inv(); } Rat operator+(const Rat r) { return Rat(n * r.d + r.n * d, d * r.d); } Rat operator-(const Rat r) { return Rat(n * r.d - r.n * d, d * r.d); } Rat operator*(const Rat r) { return Rat(n * r.n, d * r.d); } Rat operator/(const Rat r) { return Rat(n * r.d, d * r.n); } void print() const { printf("%lld/%lld ", n, d); } }; using ptr = Pt; /* global variables */ mi inv2 = mi(2).inv(); /* subroutines */ tp3 readtp3() { ll x, y, z; scanf("%lld%lld%lld", &x, &y, &z); return {x, y, z}; } ptr project(tp3 p, tp3 l) { auto [px, py, pz] = p; auto [lx, ly, lz] = l; ll vx = px - lx, vy = py - ly, vz = pz - lz; Rat rx = Rat(vx * lz, -vz); Rat ry = Rat(vy * lz, -vz); return ptr(rx, ry); } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { tp3 a = readtp3(), b = readtp3(), c = readtp3(); tp3 l = readtp3(); auto ra = project(a, l); auto rb = project(b, l); auto rc = project(c, l); //ra.x.print(); ra.y.print(); putchar('\n'); //rb.x.print(); rb.y.print(); putchar('\n'); //rc.x.print(); rc.y.print(); putchar('\n'); auto da = ptd((double)ra.x, (double)ra.y); auto db = ptd((double)rb.x, (double)rb.y); auto dc = ptd((double)rc.x, (double)rc.y); auto ma = ptmi(mi(ra.x), mi(ra.y)); auto mb = ptmi(mi(rb.x), mi(rb.y)); auto mc = ptmi(mi(rc.x), mi(rc.y)); mi s = 0; if ((db - da).cross(dc - da) >= 0.0) { s = (mb - ma).cross(mc - ma); } else { s = (mc - ma).cross(mb - ma); } s *= inv2; printf("%d\n", (int)s); } return 0; }