#include <iostream>
#define INFINITY 1000000
int main (){
    int minArr[50],minIndexArr[50];
    int count = 0;
    while (1)
    {
            
        int n = 0,m = 0;
        std::cin >> n;
        if(n == 0)break;

        int table[100][100];
        for (size_t i = 0; i < 100; i++)
        {
            for (size_t j = 0; j < 100; j++)
            {
                if(i==j){
                    table[i][j] = 0;
                }else{
                    table[i][j] = INFINITY;
                }
            }
            
        }
        
        for (size_t i = 0; i < n; i++)
        {
            int a,b,c;
            std::cin >> a >> b >> c;
            m = std::max(m,std::max(a+1,b+1));
            table[a][b] = c;
            table[b][a] = c;

        }

        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            { 
                for (size_t k = 0; k < m; k++)
                {
                    table[i][j] = std::min(table[i][k] + table[k][j], table[i][j]);
                }
            }
        }
    
        int sum[100];
        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            {
                sum[i] = 0; 
            }
        }
        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            {
                sum[i] += table[i][j]; 
            }
        }
        int min = INFINITY,minIndex = 0;
        for (size_t i = 0; i < m; i++)
        {
            if(min>sum[i]){
                min = sum[i];
                minIndex = i;
            }
        }
        
        minIndexArr[count] = minIndex;
        minArr[count] = min;
        count++;
    }
    for (size_t i = 0; i < count; i++)
    {
        std::cout << minIndexArr[i] << " " << minArr[i] << std::endl;
    }
    
}
