rendered paste bodyusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace S2
{
class Program
{
static List<List<int>> boxes = new List<List<int>>();
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<int> item = new int[] { int.Parse(strs[0]), int.Parse(strs[1]), int.Parse(strs[2]) }.ToList();
List<int> box = GetBox(item);
if (box == null)
Console.WriteLine("Item does not fit.");
else {
Console.WriteLine(box[0] * box[1] * box[2]);
}
}
}
static List<int> GetBox(List<int> item)
{
foreach (List<int> box in boxes) {
if (DimensionsMatch(box.OrderBy(i => i).ToList(), item.OrderBy(i => i).ToList()))
return box;
}
return null;
}
static bool DimensionsMatch(List<int> box, List<int> 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;
}
}
}