#include<iostream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
int main(void){
  int n;
  int maze[10][10];
  while(cin>>n,n){
    int u=0;
    rep(i,10)rep(j,10)maze[i][j]=int(1e9);
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      u=max(a,max(u,b));
      maze[a][b]=c;
      maze[b][a]=c;
    }
    u++;
    //rep(i,u)rep(j,u)cout<<maze[i][j]<<(j==u-1?'\n':' ');
    rep(i,u)rep(j,u)rep(k,u)
      maze[i][j]=min(maze[i][j],maze[i][k]+maze[k][j]);
    int res=int(1e9);
    int sum;
    int rnum=0;
    rep(i,u){
      sum=0;
      rep(j,u)if(i!=j)sum+=maze[i][j];
      if(res>sum){
	res=sum;rnum=i;
      }
    }
    cout<<rnum<<" "<<res<<endl;
  }
}