#include <iostream>  
#include <vector>  
#include<algorithm>
using namespace std; 

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // ??°??????????????¢???????´???????2?¬???????????????£??\?????????
          // d[u][v]??????e=(u,v)??????????????????????????¨???????????´??????INF????????????d[i][i]=0???

void warshall_floyd(int n) { // n???????????°
  for (int i = 0; i < n; i++)      // ?????±????????????
    for (int j = 0; j < n; j++)    // ????§???????
      for (int k = 0; k < n; k++)  // ??????
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
    int n;
    int ans_min = 100000;
    int ans[10];
    int number; 

    while(1){    
        for(int i=0; i<10; i++){
            ans[i] = 0;
        }

        d = Matrix(10, vector<int>(10, INF));
        for (int i = 0; i < 10; i++) d[i][i] = 0;
        
        cin >> n;
        if(n == 0){
            break;
        }

        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            d[from][to] = cost;
            d[to][from] = cost;
        }
        
        warshall_floyd(10);
        
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
            if (i != j && d[i][j] != INF)
                //cout << i << "??????" << j << "???????????????: " << d[i][j] << endl;
                ans[i] += d[i][j];
            }
            //cout<< ans[i]<<endl;
            if(ans_min>ans[i] &&ans[i] !=0){
                ans_min = ans[i];
                number = i;
            }
        }

        cout << number << " " << ans_min << endl;
    }
    return 0;
}