#include <iostream>
using namespace std;
#define foreach(i,n) for (int i = 0; i < n; ++i)
#define foreach1(i,n) for (int i = 1; i < n; ++i)
#define foreach_from(i,m,n) for (int i = m; i < n; ++i)

#define MAX_TOWN 10
#define MAX_N 45

int N; // the number of the pathes
int A[MAX_N];
int B[MAX_N];
int C[MAX_N];

int dt[MAX_N+1][MAX_N][MAX_N];

int main () {
    while (true) {
        cin >> N;
        if (N == 0) return 0;
        foreach (i,N) cin >> A[i] >> B[i] >> C[i];

        foreach (i,MAX_TOWN) foreach (j,MAX_TOWN) { dt[0][i][j] = i == j ? 0 : 0xffff; }
        foreach (i,N) { dt[0][A[i]][B[i]] = dt[0][B[i]][A[i]] = min(C[i], dt[0][A[i]][B[i]]); }
        foreach (i,MAX_TOWN) {
            foreach (j,MAX_TOWN) {
                foreach (k,MAX_TOWN) {
                    dt[i+1][j][k] = min(dt[i][j][k], dt[i][j][i] + dt[i][i][k]);
                }
            }
        }
        int town = -1, cost = 0xffff;
        foreach (n,MAX_TOWN) {
            int sum = 0;
            foreach (i,MAX_TOWN) { if (dt[MAX_TOWN][n][i] != 0xffff) sum += dt[MAX_TOWN][n][i]; }
            if (sum != 0 && sum < cost) { town = n; cost = sum; }
        }

        cout << town << " " << cost << endl;
    }
}