p00189 Convenient Location
Mr. A, who will graduate next spring, decided to move when he got a job. The company that finds a job has offices in several towns, and the offices that go to work differ depending on the day. So Mr. A decided to live in a town where he had a short time to go to any office.

So you decided to find the most convenient town to live in to help Mr. A.

<image>


Towns are numbered starting with 0 and there is a road between towns. Commuting time is fixed for each road. If Mr. A lives in a town, the commuting time to the office in his town is 0. At this time, consider the total commuting time to all towns. For example, if the layout of towns and roads is as shown in the figure above and Mr. A lives in town 1, the commuting time to each town will be

Town 0 to 80
0 to town 1
Up to town 2 20
Up to town 3 70
Town 4 to 90

And the sum is 260.

Enter the number of roads and information on all roads, calculate the total commuting time when living in each town, and output the number of the town that minimizes it and the total commuting time at that time. Create a program. However, if there are multiple towns with the smallest total commuting time, please output the number of the smallest town and the total commuting time at that time. The total number of towns is 10 or less, the total number of roads is 45 or less, all roads can move in both directions, and commuting time does not change depending on the direction. We also assume that there are routes from any town to all other towns.



Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:


n
a1 b1 c1
a2 b2 c2
::
an bn cn


The number of roads n (1 ≤ n ≤ 45) is given on the first line. The following n lines give information on the i-th way. ai, bi (0 ≤ ai, bi ≤ 9) is the number of the town to which the i-th road connects, and ci (0 ≤ ci ≤ 100) is the commute time for that road.

Output

For each data set, the town number that minimizes the total commuting time and the total commuting time at that time are output on one line separated by blanks.

Example

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

2 240
1 2
```python
INF = 10 ** 10
while True:
  n = int(input())
  if n == 0:
    break

  costs = [[INF] * 10 for _ in range(10)]
  for i in range(10):
    costs[i][i] = 0
  
  city = set()
  for _ in range(n):
    a, b, c = map(int, input().split())
    city = city | {a, b}
    costs[a][b] = c
    costs[b][a] = c 
  
  city = sorted(list(city))
  
  for k in range(10):
    for i in range(10):
      for j in range(10):
        costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j])
  
  min_total = INF
  best_city = -1
  for fr in city:
    total = 0
    for to in city:
      total += costs[fr][to]
    if total < min_total:
      min_total = total
      best_city = fr
  print(best_city, min_total)

```