#include <iostream>
#include <algorithm>
#define INF 0xfffffff
using namespace std;

int main() {
	int n;
	int a, b, c;
	int d[10][10];
	while (1) {
		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;
			}



		cin >> n;
		if (!n) return 0;
		for (int i = 0; i<n; i++) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;

		}

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


		int m, sc = INF;
		for (int i = 0; i<10; i++) {
			int a = 0;
			bool flag = false;
			for (int j = 0; j<10; j++) if (d[i][j] != INF && i!=j) { a += d[i][j]; flag = true; }
			if (sc>a && flag) { m = i; sc = a; }
		}
		cout << m << " " << sc << endl;
	}
}