#include <iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  while(n!=0){

  int a,b,c;
  int dc[10][10];
  int count=-1;
  int m=0;
  int s=0;
  int num=0;



	  
  for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
		if(i==j)
			dc[i][j]=0;
		else
			dc[i][j]=1000;
	}
  }

  
  for(int i=0;i<n;i++){
	cin >> a >> b >> c;
	dc[a][b]=c;
	dc[b][a]=c;
	if(count<a)
		count=a;
	if(count<b)
		count=b;
  }

  count=count+1;

  for(int l=0;l<count;l++){
	for(int i=0;i<count;i++){
		for(int j=0;j<count;j++){
			if(dc[i][l]==1000||dc[l][j]==1000)
				continue;
			else if(dc[i][j]==1000)
				dc[i][j]=dc[i][l]+dc[l][j];
			else if(dc[i][j]>dc[i][l]+dc[l][j])
				dc[i][j]=dc[i][l]+dc[l][j];
		}
	}
  }

  m=0;
  s=0;

  for(int i=0;i<count;i++)
	  s+=dc[0][i];

  for(int i=1;i<count;i++){
	  num=0;
	  for(int j=0;j<count;j++){
		  num+=dc[i][j];
	  }
	  if(num<s){
		m=i;
		s=num;
	  }
  }

  cout << m << ' ' << s << endl;

  cin >> n;
  count=-1;
  num=0;

  }

  return 0;
}
