#include <iostream>
#include <cstdlib>
#define inf 9999

using namespace std;

bool check(int *label, int n)
{
	for(int i = 0; i < n; i++){
		if(label[i] == 0){
			return true;
		}
	}
	
	return false;
}

int dij(int **a, int n, int s)
{
	int *label, current=s, next, *cost, min;

	cost = (int *)calloc(n, sizeof(int));
	label = (int *)calloc(n, sizeof(int));
	for(int i = 0; i < n; i++){
		cost[i] = a[current][i];
	}
	label[current] = 1;
	
	while(check(label, n)){
		min = inf;
		for(int i = 0; i < n; i++){
			if(min >= cost[i] && label[i] == 0){
				min = cost[i];
				next = i;
			}
		}
		label[next] = 1;
		for(int i = 0; i < n; i++){
			if(label[i] == 0 && cost[i] > a[next][i]+cost[next]){
				cost[i] = a[next][i] + cost[next];
			}
		}
		current = next;
	}
	next = 0;
	for(int i = 0; i < n; i++){
		next += cost[i];
	}
	free(label);
	free(cost);
	
	return next;
}

int main(int argc, char **argv)
{
	int **a, n, s, t, m, u;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int **)calloc(10, sizeof(int));
		for(int i = 0; i < 10; i++){
			a[i] = (int *)calloc(10, sizeof(int));
		}
		m = 0;
		for(int i = 0; i < n; i++){
			cin >> s >> t >> u;
			a[s][t] = a[t][s] = u;
			if(s > m){
				m = s;
			}
			if(t > m){
				m = t;
			}
		}
		
		for(int i = 0; i <= m; i++){
			for(int j = i+1; j <= m; j++){
				if(a[i][j] == 0){
					a[i][j] = a[j][i] = inf;
				}
			}
		}
		
		t = u = inf;
		for(int i = 0; i <= m; i++){
			s = dij(a, m+1, i);
			if(s < t){
				u = i;
				t = s;
			}
		}
		cout << u << " " << t << endl;
		for(int i = 0; i < 10; i++){
			free(a[i]);
		}
		free(a);
	}
	
	return 0;
}