#include<iostream>
#include<algorithm>
using namespace std;
const int INF = 11111111;
int main(void){
  int n,a,b,c,cost[50][50];
  int t,s,ans;

  for(;;){
    cin >> n;
    if(!n) break;
    int f[15] = {0};
    ans = INF;

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

    for(int i = 0;i < n;i++){
      cin >> a >> b >> c;
      f[a] = f[b] = 1;
      cost[a][b] = cost[b][a] = c;
    }

    for(int i = 0;i <= 10;i++){
      for(int j = 0;j <= 10;j++){
	for(int k = 0;k <= 10;k++){
	  cost[j][k] = min(cost[j][k],cost[j][i] + cost[i][k]);
	}
      }
    }

    for(int i = 0;i <= 10;i++){
      s = 0;
      if(!f[i]) continue;
      for(int j = 0;j <= 10;j++){
	if(!f[j]) continue;
	s += cost[i][j];
      }
      if(s < ans){
	ans = s;
	t = i;
      }
    }

    cout << t << " " << ans << endl;

  }
}
