#include using namespace std; using ll = long long; ll W, H, D, Vx, Vy; ll gcd(ll a, ll b) { while (b) { ll c = b; b = a % b; a = c; } return a; } ll lcm(ll a, ll b) { if (!a || !b) return 0; return a * b / gcd(a, b); } ll extgcd(ll a, ll b, ll& x, ll& y) { if (b) { ll d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } else { x = 1; y = 0; return a; } } ll rem(ll& a, ll b) { return ((a %= b) += b) %= b; } __int128 rem(__int128& a, ll b) { return ((a %= b) += b) %= b; } bool hit(ll Mx, ll My) { ll My_origin = My; ll w = 2 * W, h = 2 * H; ll a, b; ll g = extgcd(Vx, 2 * W, a, b); if (Mx % g) return false; rem(a, w); a *= Mx / g; rem(a, w / g); ll can_add_to_a = w / g; My -= Vy * (a % (h)); rem(My, h); if (My == 0) { return a <= D; } ll c, d; g = extgcd(Vy * can_add_to_a, h, c, d); assert(Vy * can_add_to_a * c + h * d == g); c *= can_add_to_a; if (My % g) return false; rem(c, lcm(h / gcd(h, Vy), can_add_to_a)); __int128 tmp_c = c; ll times_c = My / g; rem(times_c, lcm(h / gcd(h, Vy), can_add_to_a)); tmp_c *= times_c; rem(tmp_c, lcm(h / gcd(h, Vy), can_add_to_a)); c = tmp_c; return c + a <= D; } int main() { int Q; cin >> Q; while (Q--) { ll Mx, My, Hx, Hy; cin >> W >> H >> D >> Mx >> My >> Hx >> Hy >> Vx >> Vy; ll g = gcd(abs(Vx), abs(Vy)); Vx /= g; Vy /= g; D *= g; if (Vx < 0) { Vx *= -1; Hx = W - Hx; Mx = W - Mx; } if (Vy < 0) { Vy *= -1; Hy = H - Hy; My = H - My; } Vx %= 2 * W; Vy %= 2 * H; ll mx, my; bool ans = false; for (int i = 0; i < 4; i++) { if (i < 2) mx = Mx; else mx = W * 2 - Mx; if (i % 2 == 0) my = My; else my = H * 2 - My; mx -= Hx; my -= Hy; if (mx < 0) mx += W * 2; if (my < 0) my += H * 2; bool flag = hit(mx, my); ans |= flag; } cout << (ans ? "Hit" : "Miss") << endl; } }