#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

const int INF = (int)1e9 + 1;

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;

		int d[10][10];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (i == j) {
					d[i][j] = 0;
				}
				else {
					d[i][j] = INF;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
		}
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int ans = INF;
		int num = 0;
		for (int i = 0; i < 10; i++) {
			int sum = 0;
			for (int j = 0; j < 10; j++) {
				if (d[i][j] < INF) sum += d[i][j];
			}
			if (sum > 0 && ans > sum) {
				ans = sum;
				num = i;
			}
		}
		cout << num << " " << ans << endl;
	}
}
