import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.LinkedList;

public class B
{
	/* constants from the statement */
	public final double vcruise=400;
	public final int aopt=30;
	public final double gphopt=2000;
	public final double gphextra=10;
	public final double climbcost=50;

	int leg_count;
	ArrayList<Leg> legs;

	public static void main(String args[])
	{
		new B();
	}

	public B()
	{
		Scanner scan = new Scanner(System.in);

		int C=scan.nextInt();
		for(int c=1; c<=C; c++)
		{
			System.out.print("Flight " + c + ": ");

			/* read in legs */
			legs = new ArrayList<Leg>();
			leg_count = scan.nextInt();
			for(int i=0; i<leg_count; i++)
			{
				Leg l =new Leg();
				l.length = scan.nextDouble();
				l.tail20k = scan.nextDouble();
				l.tail40k = scan.nextDouble();
				legs.add(l);
			}

			TreeMap<Integer,Path> m_in = new TreeMap<Integer,Path>();
			TreeMap<Integer,Path> m_out=null;

			/* our initial state is on the groun (zero alt)
			 * with no fuel cost and no path */
			m_in.put(0,new Path());

			/* for each leg, take the output map
			 * from the last leg and feed it in */
			for(int i=0; i<leg_count; i++)
			{
				m_out=do_dp(i,m_in);

				m_in = m_out;
			}
			
			/* find the lowest and print it */
			Path lowest=null;
			for(Path p : m_out.values())
			{
				if ((lowest==null) || (p.cost < lowest.cost))
				{
					lowest=p;
				}	
			}
			lowest.print();

		}
		

	}

	class Leg
	{
		double length;
		double tail20k;
		double tail40k;

		double getTailAt(double alt)
		{
			double tail_per = (tail40k - tail20k) / 20;

			return tail20k + (tail_per * (alt - 20));
		}

	}
	class Path
	{
		double cost;
		LinkedList<Integer> alt_path;

		public Path()
		{
			cost=0.0;
			alt_path=new LinkedList<Integer>();
		}
		public Path(Path old, int leg, int old_alt, int new_alt)
		{
			cost = old.cost;
			alt_path = new LinkedList<Integer>();
			alt_path.addAll(old.alt_path);

			alt_path.add(new_alt);

			/* add climb cost if any */
			if (new_alt > old_alt)
			{
				cost += climbcost * (new_alt - old_alt);
			}

			/* figure out how much fuel this leg uses */
			double rate=gphopt + gphextra * (Math.abs(aopt - new_alt));
			double speed=vcruise + legs.get(leg).getTailAt(new_alt);
			double time=legs.get(leg).length / speed;
			double fuel = rate * time;
			cost += fuel;
		}

		public void print()
		{
			for(int i : alt_path)
			{
				System.out.print("" + i + " ");
			}
			long l_cost = (long)Math.round(cost);
			System.out.println(l_cost);
		}

	}


	/*
    * Here is the magic.
	 * We have a bunch of input sitations for this leg
	 * stored in 'input'
	 *
	 */

	TreeMap<Integer, Path> do_dp(int leg, TreeMap<Integer, Path> input)
	{
		TreeMap<Integer, Path> out = new TreeMap<Integer,Path>();

      /* for each input altitude in our input set */
		for(int start_alt : input.keySet())
		{
			Path p = input.get(start_alt);
         /* for each input, try moving to each possible altitude */
			for(int a=20; a<=40; a++)
			{
				Path p2 = new Path(p, leg, start_alt, a);

            /* if this method costs less than what was there before
				 * save it to the output */
				if ((out.get(a)==null) || (out.get(a).cost > p2.cost))
				{
					out.put(a,p2);
				}

			}
		}
		return out;
		
	}

}
