//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

using namespace std;

typedef long long ll;
typedef pair<int,int> P;



int d[10][10];
int V=10;
int INF=10000;
//d[i][i]==0;no path==INF;
void warshall_floyd(){
    for(int k=0;k<V;k++)
        for(int i=0;i<V;i++)
            for(int j=0;j<V;j++) d[i][j]= min(d[i][j],d[i][k] + d[k][j]);
}


int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0) break;
        rp(i,0,10){
            rp(j,0,10) {
                d[i][j]=INF;
                if(i==j) d[i][j]=0;
            }
        }
        rp(i,0,n) {
            int x,y,z;
            cin>>x>>y>>z;
            d[x][y]=z;
            d[y][x]=z;
        }
        warshall_floyd();
        int sum=0,ans=-1,pos=-1;
        rp(i,0,10){
            sum=0;
            rp(j,0,10){
                //cout<<d[i][j]<<" ";
                if(i==j) continue;
                if(d[i][j]!=INF) sum+=d[i][j];
            }
            //cout<<sum<<endl;
            if(ans==-1) {ans=sum;pos=i;}
            else if(sum!=0 and sum<ans){ans=sum;pos=i;}
        }
        cout<<pos<<" "<<ans<<endl;


    }
    return 0;
};