#include <iostream>
using namespace std;

int main(){
    //n...道の数
    while(true){
        int n;
        cin >> n;

        if(n==0){
            return 0;
        }

        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] = 10000;
                }
            }
        }

        int m = 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>m){
                m = a+1;
            }
            if(b+1>m){
                m = b+1;
            }
        }

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


        int mintime = 10000;
        int town = 0;

        for(int i=0;i<m;i++){
            int sumtime = 0;
            for(int j=0;j<m;j++){
                sumtime += time[i][j];
            }
            if(mintime>sumtime){
                mintime = sumtime;
                town = i;
            }
        }

        cout << town << " " << mintime << endl;
    }
    
}
