defmodule Main do def main do 1..(IO.read(:line) |> String.trim() |> String.to_integer()) |> Enum.map(fn _ -> IO.read(:line) |> String.split() |> Enum.map(&String.to_integer/1) end) |> solve |> IO.puts() end def solve(x) do solve_rec(x, {2 * 10 + 8, 3 * 10 + 9, 7 * 10 + 9}) end def solve_rec([], {a, b, c}) do cond do a == 5 * 10 + 8 && b == 4 * 10 + 8 && c == 6 * 10 + 8 -> "YES" true -> "NO" end end def solve_rec([[x1, y1, x2, y2] | t], {a, b, c}) do solve_rec( t, case x1 * 10 + y1 do ^a -> {x2 * 10 + y2, b, c} ^b -> {a, x2 * 10 + y2, c} ^c -> {a, b, x2 * 10 + y2} _ -> {a, b, c} end ) end end