#include <bits/stdc++.h>
using namespace std;

const int MAX = 10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(true){
        int n;
        cin >> n;
        if(n == 0) break;

        int E[MAX][MAX];
        for(int i = 0; i < MAX; i++){
            for(int j = 0; j < MAX; j++){
                if(i == j) E[i][j] = 0;
                else E[i][j] = 1e9;
            }
        }

        map<int, bool> mp;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            mp[a] = true;
            mp[b] = true;
            E[a][b] = c;
            E[b][a] = c;
        }
        
        for(int i = 0; i < MAX; i++){
            for(int j = 0; j < MAX; j++){
                for(int k = 0; k < MAX; k++){
                    E[j][k] = min(E[j][i] + E[i][k], E[j][k]);
                }
            }
        }

        int idx, cost = 1e9;
        for(int i = 0; i < MAX; i++){
            if(!mp[i]) continue;
            int tmp = 0;
            for(int j = 0; j < MAX; j++){
                if(mp[j]) tmp += E[i][j];
            }
            if(cost > tmp){
                idx = i;
                cost = tmp;
            }
        }

        cout << idx << ' ' << cost << endl;
    }

    return 0;
}
