#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
using namespace std;
int a1[15][15], b1[15], n;
signed main() {
	while (cin >> n, n) {
		for0(i, 10)for0(j, 10)a1[i][j] = 5000 * (i != j);
		int m = 0;
		for0(i, n) {
			int a, b, c; cin >> a >> b >> c;
			m = max({ m, a, b });
			a1[a][b] = min(c, a1[a][b]);
			a1[b][a] = a1[a][b];
		}m++;
		for0(i, m)for0(j, m)for0(k, m)a1[j][k] = min(a1[j][k], a1[j][i] + a1[i][k]);
		for0(i, m)b1[i] = 0;
		for0(i, m)for0(j, i) {
			b1[i] += a1[i][j];
			b1[j] += a1[i][j];
		}
		int ans1 = -1, ans2 = 500000;
		for0(i, m)if (ans2 > b1[i]) { ans2 = b1[i]; ans1 = i; }
		cout << ans1 << ' ' << ans2 << endl;
	}
}
