#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<climits>

using namespace std;

#define INF INT_MAX/2

int edges[100][100];
int dist[100][100];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N == 0) break;

        memset(edges,0,sizeof(edges));

        int ids[20];
        int nids = 0;

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            int ix=-1;
            int iy=-1;

            for(int l=0;l<nids;++l)
                if(ids[l]==x){
                    ix = l;
                    break;
                }

            if(ix<0){ ix = nids; ids[nids++]=x; }

            for(int l=0;l<nids;++l)
                if(ids[l]==y){
                    iy = l;
                    break;
                }

            if(iy<0){ iy = nids; ids[nids++]=y; }

            edges[ix][iy] = edges[iy][ix] = c;

        }

        for(int i=0;i<nids;++i){
            for(int j=0;j<nids;++j){
                if(i==j)
                    dist[i][j] = 0;
                else if(edges[i][j]>0)
                    dist[i][j] = edges[i][j];
                else
                    dist[i][j] = INF;
            }
        }

        for(int k=0;k<nids;++k)
            for(int i=0;i<nids;++i)
                for(int j=0;j<nids;++j)
                    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);

        int ans  = 0;
        int msum = INF;

        for(int i=0;i<nids;++i){

            int sum = 0;
            for(int j=0;j<nids;++j){
               if(dist[i][j]==INF)continue;
               sum += dist[i][j];
            }

            if(sum<=msum){

                if(sum==msum){

                    if(ids[i]<=ids[ans])
                        ans = i;

                } else {

                    ans = i;

                }

                msum = sum;

            }

        }

        cout << ids[ans] << " " << msum << endl;

    }

    return 0;

}