#include #include using namespace std; using namespace boost::multiprecision; tuple ext_gcd(int1024_t p, int1024_t q){ if(q == 0)return make_tuple(p, 1, 0); int1024_t g, x, y; tie(g, x, y) = ext_gcd(q, p%q); return make_tuple(g, x, y - (p/q)*x); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int1024_t W, H, D, Mx, My, Hx, Hy, Vx, Vy; auto calc = [&](int1024_t tx, int1024_t ty){ int1024_t A, B, C; A = 2 * W * Vy; B = -2 * H * Vx; C = ty * Vx - tx * Vy + Hx * Vy - Hy * Vx; auto g = __gcd(A, -B); if(C % g != 0)return false; A /= g, B /= g, C /= g; int1024_t x, y, m, tv, v; tie(g, x, y) = ext_gcd(B, A); m = C * y % A; v = ty + 2 * H * m - Hy; tv = ((v >= 0 ? Vy - 1 : 0) + v) / Vy; tv %= (2 * H * A + Vy - 1) / Vy; if(tv < 0)tv += (2 * H * A + Vy - 1)/ Vy; return (tv <= D); }; int t; cin >> t; while(t--){ cin >> W >> H >> D >> Mx >> My >> Hx >> Hy >> Vx >> Vy; if(Vx < 0){ Mx = W - Mx, Hx = W - Hx, Vx = -Vx; } if(Vy < 0){ My = H - My, Hy = H - Hy, Vy = -Vy; } if(Vx == 0){ if((Mx == Hx) && ((My > Hy && My - Hy <= D * Vy) || (My < Hy && 2 * H - My - Hy <= D * Vy))){ cout << "Hit" << '\n'; }else{ cout << "Miss" << '\n'; } continue; } if(Vy == 0){ if((My == Hy) && ((Mx > Hx && Mx - Hx <= D * Vx) || (Mx < Hx && 2 * W - Mx - Hx <= D * Vx))){ cout << "Hit" << '\n'; }else{ cout << "Miss" << '\n'; } continue; } auto g = __gcd(Vx, Vy); D *= g, Vx /= g, Vy /= g; int1024_t Rx = 2 * W - Mx, Ry = 2 * H - My; if(calc(Mx, My) || calc(Mx, Ry) || calc(Rx, My) || calc(Rx, Ry)){ cout << "Hit" << '\n'; }else{ cout << "Miss" << '\n'; } } }