#include <iostream>
using namespace std;

#define MAX_V 11
#define INF 1e9

int min(int a, int b){
  return a < b ? a : b;
}

int main(void){
  int n, a, b, c;
  int dp[MAX_V][MAX_V];
  
  while(true){
    cin >> n;
    if(n == 0) break;

    // ?????????
    for(int i = 0; i < MAX_V; i++)
      for(int j = 0; j < MAX_V; j++)
        dp[i][j] = INF;

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

    // ???????????£???????????????
    for(int k = 0; k < MAX_V; k++)
      for(int i = 0; i < MAX_V; i++)
        for(int j = 0; j < MAX_V; j++)
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);


    // ??????????¨????
    int minpoint, mincost = INF;
    for(int i = 0; i < MAX_V; i++){
      // ???????????????????????????????????????????±???????
      int nowcost = 0;
      for(int j = 0; j < MAX_V; j++){
        if(dp[i][j] != INF){ nowcost += dp[i][j]; } 
      }

      // ?????????????????????????????????????????????????°?????????????
      if(nowcost != 0 && mincost > nowcost){
        mincost = nowcost;
        minpoint = i;
      }
    }
    
    // ??????
    cout << minpoint << " " << mincost << endl;
    
  }

  return 0;
}