#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>

const int TOWN = 10;
const int PATH = 45;
const int INF = 100000000;

using namespace std;

int main() {
	int n;
	int a, b;

	while (cin >> n , n) {
		int num_of_town = 0;
		int g[TOWN][TOWN] = {};
		for (int i = 0; i < TOWN; i++) {
			for (int j = 0; j < TOWN; j++) {
				g[i][j] = 0;
			}
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			cin >> g[a][b];
			g[b][a] = g[a][b];
			num_of_town = max(num_of_town, max(a, b));
		}
		num_of_town++;
		//	cout << "num_of_town = " << num_of_town << "\n";

		int d[TOWN][TOWN];
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				if (i == j)			d[i][j] = 0;
				else if (g[i][j] != 0) d[i][j] = g[i][j];
				else				d[i][j] = INF;
			}
		}

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

		//cout << "\n";
		//for (int i = 0; i < num_of_town; i++) {
		//	for (int j = 0; j < num_of_town; j++) {
		//		cout << i << " " << j << " " <<  d[i][j] << "\n";
		//	}
		//}
		//cout << "\n";

		int ans_d = INF;
		int ans_t;
		int tmp = 0;
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				tmp += d[i][j];
			}
			if (ans_d > tmp) {
				ans_d = tmp;
				ans_t = i;
			}
			tmp = 0;
		}
		cout << ans_t << " " << ans_d << "\n";
	}
	
 	return 0;
}
