#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_M = 10;
const int MAX_N = 45;
const int INF = 100000000;

//input
int N;
int d[MAX_M][MAX_M];

int maxIndex;
int sum[MAX_M];

void solve(){
	for(int k = 0; k <= maxIndex; k ++){
		for(int i = 0; i <= maxIndex; i ++){
			for(int j = 0; j <= maxIndex; j ++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int index, ans = INF;
	for(int i = 0; i <= maxIndex; i ++){
		sum[i] = 0;
		for(int j = 0; j <= maxIndex; j ++){
			sum[i] += d[i][j];
		}
		if(ans > sum[i]){
			index = i;
			ans = sum[i];
		}
	}
	printf("%d %d\n", index, ans);
}

int main(int argc, char const *argv[]){

	while(scanf("%d", &N) && N != 0){
		//init
		for(int i = 0; i < MAX_M; i ++){
			fill(d[i], d[i] + MAX_M, INF);
			d[i][i] = 0;
		}
		maxIndex = 0;
		//input
		for(int i = 0; i < N; i ++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			d[a][b] = c;
			d[b][a] = c;
			maxIndex = max(maxIndex, a);
			maxIndex = max(maxIndex, b);
		}
		solve();
	}

	return 0;
}