#include<iostream>
#include<vector>

using namespace std;

struct DATA{
  int x;
  int y;
  int dis;
};

int Calculate(int, int, vector<DATA>);
void Searching(int, int, int, int, vector<int>&);

int main(){
  int i, n, x, y, d, city, ans, sum;
  vector<int> sum_data;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0, city=0; i<n; ++i){
      cin >> x >> y >> d;
      if(x != y){
	if(city < x) city = x;
	if(city < y) city = y;
	_data.x = x;
	_data.y = y;
	_data.dis = d;
	data.push_back(_data);
      }
    }
    ++city;

    for(i=0; i<city; ++i)
      sum_data.push_back(Calculate(i, city, data));

    for(i=1, ans=0, sum=sum_data[0]; i<sum_data.size(); ++i){
      if(sum > sum_data[i]){
	ans = i;
	sum = sum_data[i];
      }
    }

    cout << ans << " " << sum << endl;
    sum_data.clear();
    data.clear();
  }

  return 0;
}

int Calculate(int n, int city, vector<DATA> data){
  int i, j, sum, min, m;
  vector<int> array(city, 0);

  for(i=1, sum=0, m=n; i<city; ++i){
    for(j=0; j<data.size(); ++j){
      Searching(m, data[j].x, data[j].y, data[j].dis, array);
      Searching(m, data[j].y, data[j].x, data[j].dis, array);
    }
    array[n] = 0;

    for(j=0, min=0; j<array.size(); ++j){
      if(array[j] > 0){
	if(min == 0 || (min != 0 && min > array[j])){
	  m = j;
	  min = array[j];
	}
      }
    }
    array[m] = -array[m];
  }

  for(i=0, sum=0; i<array.size(); ++i)
    sum -= array[i];

  return sum;
}

void Searching(int n, int i, int j, int d, vector<int>& array){
  if(i == n){
    if(array[j] == 0){
      array[j] = d - array[n];
    }else if(array[j] != 0 && array[j] > d - array[n]){
      array[j] = d - array[n];
    }
  }
}