using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main(string[] args) { var q = int.Parse(Console.ReadLine()); List results = new List(); for (int i = 0; i < q; i++) { results.Add(Solve()); } foreach (var element in results) { Console.WriteLine(element); } } private static int Gcd(int a, int b) { if (b == 0) { return a; } return Gcd(b, a % b); } private static string Solve() { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var w = line[0]; var h = line[1]; var d = line[2]; var mx = line[3]; var my = line[4]; var hx = line[5]; var hy = line[6]; var vx = line[7]; var vy = line[8]; var hit = new bool[w+1,h+1]; var g = CalculateGcd(vx, vy); vx /= g; vy /= g; d *= g; for (int i = 0; i < Math.Min(d + 1, 1025); i++) { var dx = hx + vx*i; var dy = hy + vy*i; dx %= (2 * w); dy %= (2 * h); dx = Math.Abs(dx); dy = Math.Abs(dy); if (dx >= w) { dx = 2 * w - dx; } if (dy >= h) { dy= 2 * h - dy; } hit[dx, dy] = true; } if (hit[mx, my]) { return "Hit"; } return "Miss"; } private static int CalculateGcd(int vx, int vy) { int g = 0; if (vx == 0) { g = Math.Abs(vy); } else if (vy == 0) { g = Math.Abs(vx); } else { g = Gcd(Math.Abs(vx), Math.Abs(vy)); } return g; } }