#include <queue>
#include <vector>
#include <stdio.h>
using namespace std;

const int INF = 1e8;
struct edge{int to, cost;};
typedef pair<int, int> pii;
const int MAX_N = 50;
const int MAX_V = 15;
int n, V;
//ある街から出ている道
vector<edge> G[MAX_V];
int d[MAX_V];

int dijkstra(int s){
    int ret = 0;
    priority_queue<pii, vector<pii>, greater<pii> > que;
    fill(d, d+V, INF);
    
    d[s] = 0;
    que.push(pii(0, s));
    
    while(!que.empty()){
        pii p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v]+e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(pii(d[e.to], e.to));
            }
        }
    }
    for(int i=0; i<V; i++)
        ret += d[i];
    return ret;
}

void solve(){
    int ans = INF, num;
    int vmax = 0;
    int from, to, cost;
    for(int i=0; i<n; i++){
        scanf("%d%d%d", &from, &to, &cost);
        G[from].push_back(edge{to, cost});
        G[to].push_back(edge{from, cost});
        vmax = max(vmax, max(from, to));
    }
    V = vmax+1;
    for(int i=0; i<V; i++){
        int tmp;
        if ((tmp = dijkstra(i)) < ans){
            ans = tmp;
            num = i;
        }
    }
    printf("%d %d\n", num, ans);
}

int main(){
    while(scanf("%d", &n), n)
        solve();
    return 0;
}