/*
 * @Author: your name
 * @Date: 2020-08-03 05:04:45
 * @LastEditTime: 2020-08-03 05:45:31
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ACM_Introduction/2020.8.2/aoj0189.cpp
 */
#include <iostream>
#include <cstring>
using namespace std;

const int maxn = 15;
int d[maxn][maxn];
int n, a, b, c, len;
#define INF 0x3f3f3f3f
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
void floyd() {
    for(int k = 0; k <= len; ++k)
        for(int i = 0; i <= len; ++i)
            for(int j = 0; j <= len; ++j)
                d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
}

int main() {
    while(scanf("%d", &n), n) {
        int ans = INF, pos = -1, sum = 0;
        memset(d, INF, sizeof(d));
        for(int i = 0; i < maxn; ++i) 
            d[i][i] = 0;
        len = -1;
        for(int i = 0; i < n; ++i) {
            scanf("%d%d%d", &a, &b, &c);
            len = max(max(a, b), len);
            d[a][b] = d[b][a] = c;
        }
        // printf("%d", len);
        floyd();
        for(int i = 0; i <= len; ++i) {
            sum = 0;
            for(int j = 0; j <= len; j++) 
                sum += d[i][j];
            if(ans > sum) {
                ans = sum;
                pos = i;
            }
        }
        printf("%d %d\n", pos, ans);
    }
    return 0;
} 
