#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>
using namespace std;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
#define _CRT_SECURE_NO_WARNINGS
int N,V=0;
int m[10][10];
int ans = 100000;
int town = 0;
int tmp = 0;
int main() {
	while (true)
	{
		V = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				m[i][j] = 10000;
			}
		}
		scanf("%d", &N);
		if (N==0) {
			break;
		}
		for (int i = 0; i < N; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			m[a][b] = m[b][a] = c;
			V = max(V, max(a, b));
		}

		for (int i = 0; i <= V; i++) {
			for (int j = 0; j <= V; j++) {
				for (int k = 0; k <= V; k++) {
					m[j][i]=m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
				}
			}
		}
		ans = 100000;
		tmp = 0;
		for (int i = 0; i <= V; i++) {
			for (int j = 0; j <= V; j++) {
				if (i != j) {
					tmp += m[i][j];
				}
			}
			if (ans > tmp) {
				ans = tmp;
				tmp = 0;
				town = i;
			}
		}
		printf("%d %d\n", town, ans);
	}
	return 0;
}