#include <cstdio>
#include <algorithm>
using namespace std;

const int MAX_TOWN = 9;
const int INF = 1 << 20;

int d[MAX_TOWN + 1][MAX_TOWN + 1];

int main()
{
  while (true) {
    int N; scanf("%d", &N);
    if (N == 0) break;

    for (int i = 0; i <= MAX_TOWN; i++) {
      for (int j = 0; j <= MAX_TOWN; j++) {
        d[i][j] = i == j ? 0 : INF;
      }
    }

    for (int i = 0; i < N; i++) {
      int a, b, c; scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
    }

    for (int k = 0; k <= MAX_TOWN; k++) {
      for (int i = 0; i <= MAX_TOWN; i++) {
        for (int j = 0; j <= MAX_TOWN; j++) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }

    int min_t = -1, min_c = INF;

    for (int i = 0; i <= MAX_TOWN && d[i][0] != INF; i++) {
      int sum = 0;
      for (int j = 0; j <= MAX_TOWN && d[i][j] != INF; j++) {
        sum += d[i][j];
      }

      if (min_c > sum) {
        min_t = i;
        min_c = sum;
      }
    }

    printf("%d %d\n", min_t, min_c);
  }
  return 0;
}
