#include<iostream>
using namespace std;
int G[15][15];
bool solve()
{
    //initialization
    const int INF = 1000000;
    for(int i = 0; i < 15; i++)
        for(int j = 0; j < 15; j++)
        G[i][j] = INF;
    int n = 0, x = 0, y = 0, c = 0;
    cin >> n;
    if(n == 0) return false;
    for(int i = 1; i <= n; i++)
    {
        cin >> x >> y >> c;
        G[x][y] = G[y][x] = c;
    }
    //floyd
    for(int k = 0; k < 10; k++)
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    int ans = INF, ansmt = 0;
    for(int i = 0; i < 10; i++)
    {
        int tmp = 0;
        for(int j = 0; j < 10; j++)
            if(i != j && G[i][j] != INF) tmp += G[i][j];
        if(tmp != 0 && tmp < ans) {ans = tmp; ansmt = i;}
    }
    cout << ansmt << " " << ans << endl;
    return true;
}
int main()
{
    while(solve()) ;
    return 0;
}

