#include<iostream>
using namespace std;
#define MAX_VAL 100
#define INF 12345678

int d[MAX_VAL][MAX_VAL];
int V = 0;

void warshall_floyd(){
	for(int k = 0; k < V; k++)
		for(int i = 0; i < V; i++)
			for(int j = 0; j < V; j++) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}

int main(){
	int n, m, f, t, cost;
	
	while(true){
		int ans = INF, num = 0;
		cin>>n;
		
		if(!n) break;
	
	
		for(int i = 0; i < 10; i++)
			for(int j = 0; j < 10; j++)if(i==j)d[i][j]=INF;else d[i][j]=INF;
	
	
		V = 0;
	
		for(int i = 1; i <= n; i++){
			cin>>f>>t>>cost;
			d[f][t] = d[t][f] = cost;
			d[f][f] = d[t][t] = 0;
			V = max(V,max(f,t));
		}
		V++;
	
		warshall_floyd();
		
		for(int i = 0; i < V; i++){
			int sum = 0;
			for(int j = 0; j < V; j++){
				sum += d[i][j];
			}
			if(ans > sum){
				ans = sum;
				num = i;
			}
		}
		cout<<num<<" "<<ans<<endl;
	}
	return 0;
}
