#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;
int mp[50][50],n,a,b,c;
bool flag[10];
#define INF 10000000
int main()
{
    int Min;
    cin >> n;
    while(n)
    { 
        int V = 10;
        Min = INF;
        memset(flag,0,sizeof(flag));
    for(int i=0;i<50;i++)
        for(int j = 0;j<50;j++)
        {
          if(i==j)
              mp[i][j] = 0;
         else
          mp[i][j] = INF;

        }
     
    for(int i=1;i<=n;i++)
    {
         cin >> a >> b >> c;
         mp[a][b] = mp[b][a] = c;
         flag[a] = flag[b] = true;
    }
    for(int k=0;k<V;k++)
        for(int i=0;i<V;i++)
            for(int j=0;j<V;j++)
                mp[i][j]= min(mp[i][j],mp[i][k]+mp[k][j]);
   
   int MinN[11];
   memset(MinN,0,sizeof(MinN));
   for(int i=0;i<V;i++){
   	for(int j=0;j<V;j++)
   	   if(flag[j]==true)
   	  MinN[i] += mp[i][j];
   }
   
    cout << min_element(MinN,MinN+V) - MinN <<" "<<*min_element(MinN,MinN+V) <<endl;
    
    cin >> n;
    }
    return 0;
}
