#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

typedef long long int lli;
lli INF = 1000000LL;

int main() {

  array<array<lli, 10>, 10> table;
  
  while( true ){
	int n;
	cin >> n;
	if ( n == 0 ) break;

	for ( int i = 0; i < 10; i++ ) {
	  for ( int j = 0; j < 10; j++ ) {
		table[ i ][ j ] = INF;
	  }
	}
	
	int m = -1;
	for ( int i = 0; i < n; i++ ) {
	  int v1, v2, c;
	  cin >> v1 >> v2 >> c;
	  table[ v1 ][ v2 ] = c;
	  table[ v2 ][ v1 ] = c;
	  m = max( max( v1, v2 ), m );
	}
	for ( int i = 0; i < 10; i++ ) {
	  table[ i ][ i ] = 0LL;
	}

	for ( int k = 0; k <= m; k++ ) {
	  for ( int i = 0; i <= m; i++ ) {
		if ( table[ i ][ k ] >= INF ) continue;
		for ( int j = 0; j <= m; j++ ) {
		  if ( table[ i ][ j ] > table[ i ][ k ] + table[ k ][ j ] ) {
			table[ i ][ j ] = table[ i ][ k ] + table[ k ][ j ];
		  }
		}
	  }
	}
	lli ans = INF;
	int num = -1;
	for ( int i = 0; i <= m; i++ ) {
	  lli sum = 0;
	  for ( int j = 0; j <= m; j++ ) {
		sum += table[ i ][ j ]; 
	  }
	  if ( ans > sum ) {
		ans = sum;
		num = i;
	  }
	}
	cout << num << " " << ans << endl;
  }
}