using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {



           
        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                load[] loads = new load[n];
                string[] strs;
                //Store. 
                for (int i = 0; i < n; i++) {
                    strs = Console.ReadLine().Split(' ');
                    load l = new load(int.Parse(strs[0]),
                        int.Parse(strs[1]), int.Parse(strs[2]));
                    loads[i] = l;
                }
                
                //min sumkyori city
                int minSumKyori = int.MaxValue;
                int minCity = -1;
                for (int i = 0; i < 10; i++) {
                    int sumKyori = sumKyoriFrom(i, loads);
                    if (sumKyori < minSumKyori) {
                        minSumKyori = sumKyori;
                        minCity = i;
                    } 
                }

                Console.WriteLine(minCity+" "+minSumKyori);


            }
        }

        public static int sumKyoriFrom(int startCity, load[] loads) {
            int sumKyori = 0;
            if (!existStart(startCity, loads)) { return int.MaxValue; }

            node[] nodes = new node[10];
            //Node inits.
            for (int i = 0; i < 10; i++) {
                nodes[i] = new node(i);
                if (i == startCity) { nodes[i].cost = 0; }
            }
            //Dijkstra
            while (true) {
                //PickOut Min Node
                int minCost = int.MaxValue;
                node minNode = null;
                for (int i = 0; i < 10; i++) {
                    int cost = nodes[i].cost;
                    if (!nodes[i].done && cost < minCost) {
                        minCost = cost;
                        minNode = nodes[i];
                    }
                }
                //End Check
                if (minNode == null) { break; }
                //Done Check
                minNode.done = true;
                //Reload costs
                for (int i = 0; i < loads.Length; i++) {
                    load l = loads[i];
                    if (l.a != minNode.cityNum && l.b != minNode.cityNum) { continue; }
                    int targetNum = (l.a==minNode.cityNum)? l.b : l.a;
                    node target = nodes[targetNum];
                    if (target.cost > minNode.cost + l.c) { target.cost = minNode.cost + l.c; }
                }
            }

            //summation
            for (int i = 0; i < 10; i++) {
                if (nodes[i].done) { sumKyori += nodes[i].cost; } 
            }
            return sumKyori;
        }




        public static bool existStart(int startCity, load[] loads) {
            bool flag = false;
            for (int i = 0; i < loads.Length; i++) {
                if (loads[i].a == startCity) { flag = true; }
            }

            return flag;
        }
        



        public class node {
            public int cityNum;
            public node(int num) { cityNum = num; }
            public bool done = false;
            public int cost = int.MaxValue;

        }
        
        public class load {
            public int a, b, c;
            public load(int a, int b, int c) {
                this.a = a; this.b = b; this.c = c;
            }
            public bool startFrom(int start) { return start == a; }
        }
       


    }
}

Measured memory_bytes: 11800