Title: Convenient Town

A graduate, A, plans to move for a new job. The company has offices in several towns, and A needs to find the most convenient town to live in, considering commuting times to different offices. Given town numbers and commuting times between them, find the town with the shortest total commuting time. If multiple towns have the same minimum total commuting time, output the town with the smallest number. Town count is at most 10, and road count is at most 45. All roads are bidirectional, and commuting times are the same in both directions. There is a path from any town to any other town.

Input:
Multiple datasets are given. Each dataset has the format:
n
a1 b1 c1
a2 b2 c2
...
an bn cn

Output:
For each dataset, output the town number with the minimum total commuting time and the corresponding total commuting time.

Sample Input:
6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0

Output for the Sample Input:
2 240
1 2

# Buggy version:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189
AC
"""
import sys
from sys import stdin
input = stdin.readline


def warshallFloyd(V, dp):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                dp_ik = dp[i][k]
                dp_kj = dp[k][j]
                if dp[i][j] < dp_ik + dp_kj:
                    dp[i][j] = dp_ik + dp_kj


def main(args):
    while True:
        n_max = 9+1
        n = int(input())
        if n == 0:
            break
        dp = [[float('inf')] * n_max for _ in range(n_max)]
        for i in range(n_max):
            dp[i][i] = 0

        max_town = 0
        for _ in range(n):
            a, b, c = map(int, input().split())
            dp[a][b] = c
            dp[b][a] = c
            max_town = max(max_town, a, b)

        warshallFloyd(max_town + 1, dp)


        min_dist = float('inf')
        town_live = -1
        for i, d in enumerate(dp[:max_town+1]):
            sum_dist = 0
            for ele in d[:max_town+1]:
                sum_dist += ele
            if sum_dist < min_dist:
                min_dist = sum_dist
                town_live = i

        print('{} {}'.format(town_live, min_dist))



if __name__ == '__main__':
    main(sys.argv[1:])
    

# Fixed version:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189
AC
"""
import sys
from sys import stdin
input = stdin.readline


def warshallFloyd(V, dp):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                dp_ik = dp[i][k]
                dp_kj = dp[k][j]
                if dp[i][j] > dp_ik + dp_kj:
                    dp[i][j] = dp_ik + dp_kj


def main(args):
    while True:
        n_max = 9+1
        n = int(input())
        if n == 0:
            break
        dp = [[float('inf')] * n_max for _ in range(n_max)]
        for i in range(n_max):
            dp[i][i] = 0

        max_town = 0
        for _ in range(n):
            a, b, c = map(int, input().split())
            dp[a][b] = c
            dp[b][a] = c
            if a > max_town:
                max_town = a
            if b > max_town:
                max_town = b

        warshallFloyd(max_town + 1, dp)


        min_dist = float('inf')
        town_live = -1
        for i, d in enumerate(dp[:max_town+1]):
            sum_dist = sum(d[:max_town+1])
            if sum_dist < min_dist:
                min_dist = sum_dist
                town_live = i

        print('{} {}'.format(town_live, min_dist))



if __name__ == '__main__':
    main(sys.argv[1:])

# Buggy version:
road = int(input())
while road > 0:
    answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
    city = 0
    for _ in range(road):
        c1, c2, w = (int(n) for n in input().split(" "))
        answer[c1][c2] = w
        answer[c2][c1] = w
        city = max(city, c1, c2)
    for i in range(city):
        for j in range(city):
            for k in range(city):
                answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
    sum_ans = [-1 , float("inf")]
    for i in range(city):
        if sum(answer[i][:city]) < sum_ans[1]:
            sum_ans = [i, sum(answer[i][:city])]
    print(*sum_ans)
    road = int(input())

# Fixed version:
import sys
from sys import stdin
input = stdin.readline

road = int(input())
while road > 0:
    answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
    city = 0
    for _ in range(road):
        c1, c2, w = (int(n) for n in input().split(" "))
        answer[c1][c2] = w
        answer[c2][c1] = w
        city = max(city, c1, c2)
    city += 1
    for i in range(city):
        for j in range(city):
            for k in range(city):
                answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
    sum_ans = [-1 , float("inf")]
    for i in range(city):
        if sum(answer[i][:city]) < sum_ans[1]:
            sum_ans = [i, sum(answer[i][:city])]
    print(*sum_ans)
    road = int(input())