import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;


public class ANARC_2010_D_Alt
{
	BufferedReader in;
	Scanner inr;
	PrintWriter out;

	void initIO() throws IOException
	{
		inr = new Scanner(System.in);
		in = new BufferedReader(new InputStreamReader(
				System.in));
		out = new PrintWriter(new OutputStreamWriter(System.out));
	}
	
	void solve() throws Exception
	{
		int nt = 0;
		while (true)
		{
			int n = nextInt();
			if (n == 0)
				break;
			int a[][] = new int[n][3];
			long dp[][] = new long[n][3];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < 3; j++)
					a[i][j] = nextInt();
			dp[0][0] = Integer.MAX_VALUE * 1000001L;
			dp[0][1] = a[0][1];
			dp[0][2] = a[0][1] + a[0][2];
			for (int i = 1; i < n; i++)
			{
				dp[i][0] = Math.min(dp[i-1][0], dp[i-1][1]) + a[i][0];
				dp[i][1] = Math.min(Math.min(Math.min(dp[i-1][0], dp[i-1][1]), dp[i-1][2]), dp[i][0]) + a[i][1];
				dp[i][2] = Math.min(Math.min(dp[i-1][1], dp[i-1][2]), dp[i][1]) + a[i][2];
			}
			System.out.println("" + (++nt) + ". " + dp[n-1][1]);
		}
	}

	void run() throws Exception
	{
		initIO();
		solve();
		out.flush();
	}

	int nextInt()
	{
		return inr.nextInt();
	}
	
	String nextLine()
	{
		return inr.nextLine();
	}
	
	String nextString()
	{
		return inr.next();
	}

	public static void main(String[] args) throws Exception
	{
		new ANARC_2010_D_Alt().run();
	}
}
