#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 10;
const int M = 10;
const int INF = 0x3f3f3f3f;
int d[N][N];
int n;
/*void input()
{
    for (int i = 0; i < N; i ++)
        fill(d[i], d[i]+N, INF);
    int m;
    cin >> m;
    n = 0;
    while ( m-- ) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        d[a][b] = d[b][a] = c;
        n = max(max(n, a+1), b+1);
    }
}*/
void solve()
{
    for (int k = 0; k < n; k ++) {
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < n; j ++) {
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }

    int sum, msum = INF;
    int id = 0;
    for (int i = 0; i < n; i ++) {
        sum = 0;
        for (int j = 0; j < n; j ++) {
            if (i == j) continue;
            sum += d[i][j];
        }
        if (sum < msum) {
            msum = sum;
            id = i;
        }
    }
    printf("%d %d\n", id, msum);
}
int main(void)
{
    int m;
    while ( cin >> m && m ) {
        for (int i = 0; i < N; i ++)
            fill(d[i], d[i]+N, INF);
        n = 0;
        while ( m-- ) {
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            d[a][b] = d[b][a] = c;
            n = max(max(n, a+1), b+1);
        }
        solve();
    }
    re