#include <bits/stdc++.h>

using namespace std;

const int maxn = 10;
const int inf = (INT_MAX>>1) - 10;
int cost[maxn][maxn];
int ct,x,y,z;
map<int,bool> has;

void solve(){

    has.clear();
    for(int i=0;i<maxn;i++){
        fill(cost[i],cost[i]+maxn,inf);
        cost[i][i] = 0;
    }
    while(ct--){
        cin>>x>>y>>z;
        cost[x][y] = cost[y][x] = z;
        has[x] = has[y] = true;
    }
    for(int k=0;k<maxn;k++)
        for(int i=0;i<maxn;i++)
            for(int j=0;j<maxn;j++)
                cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);

    pair<int,int> res = make_pair(-1,INT_MAX);
    int ct;
    for(auto p = has.begin(); p != has.end(); p++){
        ct = 0;
        for(auto x = has.begin(); x != has.end(); x++) ct += cost[(*p).first][(*x).first];
        cout<<ct<<endl;
        if(ct < res.second) res = make_pair((*p).first,ct);
    }
    cout<<res.first<<' '<<res.second<<endl;
}
int main(){

    while(cin>>ct and ct) solve();

//    system("pause");
    return 0;
}
