#include <iostream>

#define MAX 10
#define INF 2000000
using namespace std;

int d[MAX][MAX];
int n, num_ver = 0;
int min_t = INF;
int min_ver;

void init();
void input();
void wf();

int main(){

  while(cin >> n, n){
    init();
    input();  
    wf();
    
   
    for(int i = 0; i <= num_ver; i++){
      int tmp = 0;
      for(int j = 0; j <= num_ver; j++){
	tmp += (i<j)? d[i][j] : d[j][i];
      }
      if(min_t > tmp) {min_t = tmp; min_ver = i;}
    }
    cout << min_ver << " " << min_t << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      d[i][j] = (i==j)? 0: INF;
    }
  }
}

void input(){
  for(int i = 0; i < n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
    if(num_ver < b) num_ver = b;
  }
}

void wf(){
  for(int i = 0; i <= num_ver; i++){
    for(int j = 0; j <= num_ver; j++){
      for(int k = 0; k <= num_ver; k++){
	d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}