#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
const int max_n = 15;
const int INF = 0x3f3f3f3f;
int dis[max_n][max_n];

/*********************************************************/

void floyd(int m){
    for(int k = 0; k <= m; ++k)
        for(int i = 0; i <= m; ++i)
            for(int j = 0; j <= m; ++j)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}

int main(){
    ios::sync_with_stdio(false);
    for(int i = 0; i < max_n; ++i) fill(dis[i], dis[i] + max_n, INF), dis[i][i] = 0;
    while(cin >> n && n){
        int m = 0;
        while(n--){
            int x, y, d;
            cin >> x >> y >> d;
            m = max(m, x);
            m = max(m, y);
            dis[x][y] = dis[y][x] = d;
        }
        floyd(m);
        int ans = INF, index = 0;
        for(int i = 0; i <= m; ++i){
            int temp = 0;
            for(int j = 0; j <= m; ++j) temp += dis[i][j];
            if(temp < ans){
                ans = temp;
                index = i;
            }
        }
        cout << index << " " << ans << endl;
    }
    return 0;
}