#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define pcnt __builtin_popcount #define show(x) cout<<#x<<" = "< pii; typedef vector vi; typedef vector vvi; typedef vector vpii; typedef set si; typedef pair pll; typedef vector vl; typedef vector vvl; typedef vector vpll; typedef set sl; typedef __int128_t lll; typedef pair plll; typedef vector vlll; templatestring join(vector&v) {stringstream s;FOR(i,0,sz(v))s<<' '<b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;} int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;} void dout(double d){printf("%.12f\n",d);} const int iinf = 1e9; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; struct Ieq{ lll gcd(lll a,lll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;} lll abs(lll a){return (a<0 ? -a : a);} plll _solve(lll x,lll y,lll z){ if(x==1)return plll(z,0); lll m = y/x, _y = y%x, f, s, d; plll t = _solve(_y,x,z); f = t.second - m*t.first; s = t.first; if(f<0){ d = abs(f/y); f += d*y; s -= d*x; } if(s<0){ d = abs(s/x); s += d*x; f-=d*y; } return plll(f,s); } plll solve(lll x, lll y, lll z){ if(z==0)return plll(0,0); if(z<0){ x*=-1; y*=-1; z*=-1; } ll _x=abs(x), _y=abs(y), g=gcd(_x,_y); if(g<1||z%g>0) return plll(0, 0); _x /= g; _y /= g; z /= g; if(_x > _y) swap(_x, _y); plll t = _solve(_x,_y,z); if(abs(x)>abs(y)) swap(t.first, t.second); if(x < 0)t.first *= -1; if(y < 0)t.second *= -1; return t; } }; Ieq ieq; int q; bool hit(lll w, lll h, lll d, lll x, lll y, lll vx, lll vy){ lll z = y*vx - x*vy; if(z == 0){ return (x <= vx * d &&y <= vy * d); }else{ plll t = ieq.solve(w*vy, -h*vx, z); if(t.fi == 0 && t.se == 0) return false; lll g = gcd(w*vy, h*vx), _x = h*vx/g, _y = w*vy/g; if(t.fi < 0){ lll dd = -t.fi/_x + 1; t.fi += dd * _x; t.se += dd * _y; } if(t.se < 0){ lll dd = -t.se/_y + 1; t.fi += dd * _x; t.se += dd * _y; } { lll dd = t.fi/_x, dd2 = t.se/_y; if(dd2 < dd) dd = dd2; t.fi -= dd * _x; t.se -= dd * _y; } return (t.fi * w + x <= vx * d && t.se * w + y <= vy * d); } } main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> q; FOR(j, 0, q){ ll w, h, d, mx, my, hx, hy, vx, vy, _mx, _my; cin >> w >> h >> d >> mx >> my >> hx >> hy >> vx >> vy; if(vx < 0){ mx = w - mx; hx = w - hx; vx *= -1; } if(vy < 0){ my = h - my; hy = h - hy; vy *= -1; } w *= 2; h *= 2; bool hi = false; FOR(i, 0, 4){ _mx = ((i&1) ? (w - mx) : mx) - hx; _my = ((i&2) ? (h - my) : my) - hy; if(_mx < 0) _mx += w; if(_my < 0) _my += h; if(hit(w, h, d, _mx, _my, vx, vy)){ cout << "Hit\n"; hi = true; break; } } if(!hi) cout << "Miss\n"; } return 0; }