#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, a, b, c, g[10][10], d[10][10], s[10];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break; m = 0;
		for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) g[i][j] = 99999999, d[i][j] = 999999999;
		for (int i = 0; i < n; i++) scanf("%d%d%d", &a, &b, &c), g[a][b] = c, g[b][a] = c, m = max({ a + 1, b + 1, m });
		for (int i = 0; i < m; i++) d[i][i] = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < m; k++) {
					d[j][k] = min(d[j][k], d[j][i] + g[i][k]);
				}
			}
		}
		int p = 0;
		for (int i = 0; i < m; i++) { s[i] = 0; for (int j = 0; j < m; j++) s[i] += d[i][j]; }
		for (int i = 0; i < m; i++) if (s[i] < s[p]) p = i;
		printf("%d %d\n", p, s[p]);
	}
	return 0;
}