import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { int Q = readln.chomp.to!int; foreach (i; 0..Q) { auto s = readln.split.map!(to!int); int W, H, D, mx, my, hx, hy, vx, vy; W = s[0], H = s[1], D = s[2], mx = s[3], my = s[4]; hx = s[5], hy = s[6], vx = s[7], vy = s[8]; auto g = gcd(abs(vx), abs(vy)); auto used = new bool[][][][](W+1, H+1, 2, 2); bool hit = false; bool end = false; foreach (_; 0..D) { foreach (j; 0..g) { hx += vx/g, hy += vy/g; if (hx > W) { int p = (hx - W) / W; int q = (hx - W) % W; if (p % 2 == 1) { hx = W - q; vx = -abs(vx); } else { hx = q; vx = abs(vx); } } else if (hx < 0) { int p = (-hx) / W; int q = (-hx) % W; if (p % 2 == 0) { hx = W - q; vx = -abs(vx); } else { hx = q; vx = abs(vx); } } if (hy > H) { int p = (hy - H) / H; int q = (hy - H) % H; if (p % 2 == 1) { hy = H - q; vy = -abs(vy); } else { hy = q; vy = abs(vy); } } else if (hy < 0) { int p = (-hy) / H; int q = (-hy) % H; if (p % 2 == 0) { hy = H - q; vy = -abs(vy); } else { hy = q; vy = abs(vy); } } if (hx == mx && hy == my) { hit = true; end = true; break; } if (used[hx][hy][vx>0][vy>0]) { end = true; break; } used[hx][hy][vx>0][vy>0] = true; } if (end) break; } writeln(hit ? "Hit" : "Miss"); } }