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

public class BArr
{
	/* 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 BArr();
	}

	public BArr()
	{
		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);
			}
			Spot spots[][]=new Spot[leg_count+1][41];

			/* assume we climb to at least alt 20 at start */
			spots[0][20]=new Spot(climbcost * 20,20);

			for(int leg=0; leg<leg_count; leg++)
			{
				/* for every possible start of this leg */
				for(int alt_start=20; alt_start <= 40; alt_start++)
				{
					if (spots[leg][alt_start] != null)
					{
						/* go to every possible final alt */
						for(int alt_end=20; alt_end <= 40; alt_end++)
						{

							double rate=gphopt + gphextra * (Math.abs(aopt - alt_end));
							double speed=vcruise + legs.get(leg).getTailAt(alt_end);
							double time=legs.get(leg).length / speed;
							double fuel = rate * time;
                     
							/* add climb cost if any */
							if (alt_end > alt_start)
							{
								fuel += climbcost * (alt_end - alt_start);
							}
							double cost = spots[leg][alt_start].cost + fuel;


							Spot s = new Spot(cost, alt_start);
							if ((spots[leg+1][alt_end] == null) || (s.cost < spots[leg+1][alt_end].cost))
							{
								/* only save the ones that are better */
								spots[leg+1][alt_end] = s;
							}
						}

					}
				}

			}

			Spot least=null;
			int last_alt=0;

			for(int a=20; a<=40; a++)
			{
				if ((least==null) || (least.cost > spots[leg_count][a].cost))
				{
					least=spots[leg_count][a];
					last_alt=a;
				}

			}

			LinkedList<Integer> path=null;
			path=new LinkedList<Integer>();


			for(int leg=leg_count; leg>0; leg--)
			{
				path.addFirst(last_alt);
				last_alt = spots[leg][last_alt].last_alt;
			}
			for(int a : path)
			{
				System.out.print("" + a + " ");
			}
			long cost = (long)Math.round(least.cost);
			System.out.println(cost);

		}
		

	}

	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 Spot
	{
		double cost;
		int last_alt;

		Spot(double cost, int last_alt)
		{
			this.cost = cost;
			this.last_alt = last_alt;
		}

	}

}
