#include <iostream>
#define INFINITY (1 << 30)
#define MAX_N 10

using namespace std;

int n ;
long long  int d[MAX_N][MAX_N] = {},road[MAX_N][MAX_N] = {};;

int main() {
  int city, mincity;
  long long int  temp1, temp2, temp3, alt,costtime, cost;
  while (1) {
    road[MAX_N][MAX_N] = {};
    d[MAX_N][MAX_N] = {};
    cin >> n;
    if (n == 0) break;
    city = mincity = 0;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2 >> temp3;
      if (road[temp1][temp2] != 0) {
        if (road[temp1][temp2] > temp3) {
          road[temp1][temp2] = temp3;
          road[temp2][temp1] = temp3;
        }
      }
      else {
        road[temp1][temp2] = temp3;
        road[temp2][temp1] = temp3;
      }
      if (city < temp1 || city < temp2) { city = (temp1 > temp2) ? temp1 : temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i < city; ++i) {
      for (int j = 0; j < city; ++j) {
        if (i != j) d[i][j] = INFINITY;
        if (road[i][j] != 0) d[i][j] = road[i][j];
      }
    }


    for (int i = 0; i < city; ++i)
      for (int j = 0; j < city; ++j)
        for (int k = 0; k < city; ++k) {
          if (d[j][i] != INFINITY && d[i][k] != INFINITY) {
            alt = d[j][i] + d[i][k];
            if (alt < d[j][k]) d[j][k] = alt;
          }
        }


    for (int i = 0; i < city; ++i) {
      cost = 0;
      for (int j = 0; j < city; ++j) {
        cost += d[i][j];
        //cout << d[i][j] << " ";
      }
      //cout << endl;
      if (i == 0) costtime = cost;
      if (costtime > cost) {
        costtime = cost;
        mincity = i;
      }
    }
    cout << mincity << " " << costtime << endl;

  }


  return 0;
}