import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; struct point { int x, y; point opBinary(string op)(point rhs) { static if (op == "+") return point(x + rhs.x, y + rhs.y); else static if (op == "-") return point(x - rhs.x, y - rhs.y); } } void main() { auto q = readln.chomp.to!int; foreach (_; 0..q) { auto rd = readln.split.map!(to!int); auto w = rd[0], h = rd[1], d = rd[2]; auto pm = point(rd[3], rd[4]), ph = point(rd[5], rd[6]), pv = point(rd[7], rd[8]); if (pv.x < 0) { pm = point(w - pm.x, pm.y); ph = point(w - ph.x, ph.y); pv = point(-pv.x, pv.y); } if (pv.y < 0) { pm = point(pm.x, h - pm.y); ph = point(ph.x, h - ph.y); pv = point(pv.x, -pv.y); } auto hw = h * w / gcd(h, w); auto buf = new bool[][](2 * h, 2 * w); auto vg = gcd(pv.x, pv.y); foreach (t; 1..min(d, 2 * hw) + 1) { if (pv.x == 0 || pv.y == 0 || pv.x == pv.y) { foreach (u; 0..max(pv.x, pv.y)) { auto x = (ph.x + pv.x * t + u * (pv.x == 0 ? 0 : 1)) % (2 * w); auto y = (ph.y + pv.y * t + u * (pv.y == 0 ? 0 : 1)) % (2 * h); buf[y][x] = true; } } else { foreach (u; 1..vg + 1) { auto x = (ph.x + pv.x * t + pv.x / vg * u) % (2 * w); auto y = (ph.y + pv.y * t + pv.y / vg * u) % (2 * h); buf[y][x] = true; } } } auto rx = 2 * w - pm.x; auto ry = 2 * h - pm.y; auto r = buf[pm.y][pm.x] || buf[ry][pm.x] || buf[pm.y][rx] || buf[ry][rx]; writeln(r ? "Hit" : "Miss"); } }