object Main extends App {
    val in = io.Source.stdin.getLines
    for (n <- in if n != "0") {
        var town_size = 0
        val es = in.take(n.toInt).flatMap(e => {
            val Array(a, b, c) = e.split(" ").map(_.toInt)
            town_size = town_size max a max b
            Seq((a, b, c), (b, a, c))
        }).toList
        val costs = for (town <- (0 to town_size)) yield {
            val g = Array.fill(town_size+1)(Int.MaxValue-100)
            g(town) = 0
            var flag = true
            while(flag) {
                flag = false
                for (e <- es) if (g(e._1) + e._3 < g(e._2)) {g(e._2) = g(e._1) + e._3; flag = true}
            }
            Seq(town, g.sum)
        }
        println(costs.minBy(_(1)).mkString(" "))
    }
}