#include<iostream>
using namespace std;

const int MAX_TOWN = 10;
const int INF = 1000000;

int dist[MAX_TOWN][MAX_TOWN];

void minify() {
  for (int k = 0; k < 10; k++)
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int sum_of_dist(int t) {
  int sum = 0;
  for (int i = 0; i < 10; i++)
    sum += (dist[t][i] == INF)? 0:dist[t][i];

  return (sum == 0)? INF:sum;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    int a, b, c;

    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = (i == j)? 0:INF;

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      dist[a][b] = dist[b][a] = c;
    }

    minify();

    int min_dist = INF, min_town = 0;
    for (int t = 0; t < 10; t++) {
      if (min_dist > sum_of_dist(t)) {
        min_town = t;
        min_dist = sum_of_dist(t);
      } 
    }

    cout << min_town << " " << min_dist << endl;
  }
}