using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace S2 { class Program { static List> boxes = new List>(); static void Main(string[] args) { int times; times = int.Parse(Console.ReadLine()); for (int i = 0; i < times; i++) { string[] strs = Console.ReadLine().Split(' '); boxes.Add(new int[] { int.Parse(strs[0]), int.Parse(strs[1]), int.Parse(strs[2]) }.ToList()); } times = int.Parse(Console.ReadLine()); for (int i = 0; i < times; i++) { string[] strs = Console.ReadLine().Split(' '); List item = new int[] { int.Parse(strs[0]), int.Parse(strs[1]), int.Parse(strs[2]) }.ToList(); List box = GetBox(item); if (box == null) Console.WriteLine("Item does not fit."); else { Console.WriteLine(box[0] * box[1] * box[2]); } } } static List GetBox(List item) { foreach (List box in boxes) { if (DimensionsMatch(box.OrderBy(i => i).ToList(), item.OrderBy(i => i).ToList())) return box; } return null; } static bool DimensionsMatch(List box, List item) { foreach (int d1 in item) { int match = 0; for (int i = 0; i < box.Count; i++) { int d2 = box[i]; if (d1 <= d2) { match++; } } if (match == 3) return true; } return false; } } }