#include <bits/stdc++.h>

using namespace std;


int MapData[11][11];
int Result[11];

void calculation(int maxNode) {
	for (int i = 0; i < maxNode; i++) {
		for (int j = 0; j < maxNode; j++) {
			Result[i] += MapData[i][j];
		}
	}
}

void findAllRoad(int maxNode) {
	for (int i = 0; i < maxNode; i++) {
		for (int j = 0; j < maxNode; j++) {
			for (int k = 0; k < maxNode; k++) {
				MapData[j][k] = min(MapData[j][k], MapData[j][i] + MapData[i][k]);
				if (j == k) {
					MapData[j][k] = 0;
				}
			}
		}
	}
}

void init() {
	for (int i = 0; i < 11; i++) {
		for (int j = 0; j < 11; j++) {
			MapData[i][j] = 9999;
		}
	}
	memset(Result, 0, sizeof(Result));
}

int main() {
	int n, a, b, c, minTotal, minNum, cnt;

	while (cin >> n, n) {
		init();
		cnt = -1;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			MapData[a][b] = c;
			MapData[b][a] = c;
			cnt = max(cnt, a);
			cnt = max(cnt, b);
		}
		findAllRoad(cnt+1);
		calculation(cnt+1);

		minNum = -1;
		minTotal = INT_MAX;
		for (int i = 0; i < 11; i++) {
			if (Result[i] != 0 && Result[i] < minTotal) {
				minTotal = Result[i];
				minNum = i;
			}
		}
		cout << minNum << " " << minTotal << endl;
	}
	return 0;
}
