#include #define REP(i, x, n) for(int i = x; i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define F first #define S second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; int getDir(int x, int y) { if(x >= 0 && y >= 0) return 0; if(x >= 0 && y < 0) return 1; if(x < 0 && y >= 0) return 2; if(x < 0 && y < 0) return 3; } int main() { // ios_base::sync_with_stdio(false); int Q; cin >> Q; rep(i, Q) { int W, H, D, mx, my, hx, hy, vx, vy; cin >> W >> H >> D >> mx >> my >> hx >> hy >> vx >> vy; int d = __gcd(abs(vx), abs(vy)); vx /= d; vy /= d; D *= d; bool visited[H + 1][W + 1][4]; memset(visited, false, sizeof(visited)); visited[hy][hx][getDir(vx, vy)] = true; rep(j, D) { int nx = hx + vx; int ny = hy + vy; while(nx < 0 || W < nx || ny < 0 || H < ny) { if(nx < 0) { vx *= -1; nx = abs(nx); } if(W < nx) { vx *= -1; nx = 2 * W - nx; } if(ny < 0) { vy *= -1; ny = abs(ny); } if(H < ny) { vy *= -1; ny = 2 * H - ny; } } if(visited[ny][nx][getDir(vx, vy)]) break; visited[ny][nx][getDir(vx, vy)] = true; hx = nx; hy = ny; } bool ans = false; rep(j, 4) ans |= visited[my][mx][j]; cout << (ans ? "Hit" : "Miss") << endl; } return 0; }