#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)
const int INF = (int)1e9;

int main() {
    for(int N; cin >> N, N; ) {
        static int D[10][10];
        REP(i,10) REP(j,10) D[i][j] = INF;
        REP(i,10) D[i][i] = 0;
        set<int> town;
        REP(i,N) {
            int a, b, c; cin >> a >> b >> c;
            town.insert(a);
            town.insert(b);
            D[a][b] = c;
            D[b][a] = c;
        }
        REP(k,10) REP(i,10) REP(j,10) D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
        int t = -1;
        int d = INF;
        for(auto it : town) {
            int ds = 0;
            for(auto it2 : town) {
                ds += D[it][it2];
            }
            if(ds < d) {
                t = it;
                d = ds;
            }
        }
        cout << t << ' ' << d << endl;
    }
}