#include <iostream>
using namespace std;

#define INF int(100100)

int main(){
    while(1){
        int n;
        cin >> n;
        
        if(n==0)  break;          //終了の判断

        int time[10][10];

        for(int i=0;i<10;i++){           //配列の初期化
            for(int j=0;j<10;j++){
                if(i==j)
                    time[i][j] = 0;
                else
                    time[i][j] = INF;
            }
        }

        int count(0);
        for(int i=0;i<n;i++){           //配列の設定
            int a,b,c;
            cin >> a >> b >> c;
            time[a][b] = time[b][a] = c;
            if(a+1>count)   count = a+1;
            if(b+1>count)   count = b+1;
        }

        for(int k=0;k<count;k++){           //最短距離に書き換え
            for(int i=0;i<count;i++){
                for(int j=0;j<count;j++){
                    if(time[i][j]>(time[i][k]+time[k][j]))
                        time[i][j] = time[i][k]+time[k][j];
                }
            }
        }

        int v(0),atotal(INF);
        for(int i=0;i<count;i++){
            int total(0);
            for(int j=0;j<count;j++){
                total += time[i][j];
            }
            if(total<atotal){
                v = i;
                atotal = total;
            }
        }
        cout << v << " " << atotal << endl;
    }

    return 0;
}
