// {{{ Templates #include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using bigint = __int128_t; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; template constexpr T INF = numeric_limits::max() / 100; // }}} template T gcd(const T a, const T b) { return (b != 0) ? gcd(b, a % b) : a; } template T extgcd(const T a, const T b, T& x, T& y) // ax+by=gcd(a,b) { T d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } struct FieldInfo { bigint W; bigint H; bigint D; bigint MX; bigint MY; bigint HX; bigint HY; bigint VX; bigint VY; }; bigint absol(const bigint& a) { return (a < 0) ? -a : a; } bool hit(const FieldInfo& f, const bool oddv, const bool oddh) { const bigint W = f.W; const bigint H = f.H; const bigint D = f.D; const bigint MX = f.MX; const bigint MY = f.MY; const bigint HX = f.HX; const bigint HY = f.HY; const bigint VX = f.VX; const bigint VY = f.VY; if (VX == 0) { if (MX != HX) { return false; } else { const bigint dist = (VY > 0) ? ((HY <= MY) ? MY - HY : 2 * H - (MY + HY)) : ((HY >= MY) ? HY - MY : MY + HY); return dist <= absol(VY) * D; } } else if (VY == 0) { if (MY != HY) { return false; } else { const bigint dist = (VX > 0) ? ((HX <= MX) ? MX - HX : 2 * W - (MX + HX)) : ((HX >= MX) ? HX - MX : MX + HX); return dist <= absol(VX) * D; } } const bigint K = VY * HX - VX * HY + ((oddv) ? -VY * MX : VY * MX) + ((oddh) ? VX * MY : -VX * MY); const bigint A = 2 * VY * W; const bigint B = -2 * VX * H; bigint m, n; bigint g = extgcd(A, B, m, n); if (K % g != 0) { return false; } m *= K / g; n *= K / g; bigint x = 2 * m * W - HX + ((oddv) ? MX : -MX); const bigint delta = absol(2 * H * W * VX / g); x = ((x % delta) + delta) % delta; return x <= D * VX; } int main() { cin.tie(0); ios::sync_with_stdio(false); int Q; cin >> Q; for (int q = 0; q < Q; q++) { FieldInfo f; ll w, h, d, mx, my, hx, hy, vx, vy; cin >> w >> h >> d >> mx >> my >> hx >> hy >> vx >> vy; f.W = (bigint)(w); f.H = (bigint)(h); f.D = (bigint)(d); f.MX = (bigint)(mx); f.MY = (bigint)(my); f.HX = (bigint)(hx); f.HY = (bigint)(hy); f.VX = (bigint)(vx); f.VY = (bigint)(vy); bool hitflag = false; for (int i = 0; i < 4; i++) { const bool oddv = (bool)(i / 2); const bool oddh = (bool)(i % 2); if (hit(f, oddv, oddh)) { hitflag = true; break; } } if (hitflag) { cout << "Hit" << endl; } else { cout << "Miss" << endl; } } return 0; }