#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>

using namespace std;
#define LL long long
#define LLBIG 1999999999999999999
#define INTBIG 100000000
#define VI vector<int>
#define VVI vector<vector<int>>

int main() {
	while (true) {
		int n; cin >> n;
		if (!n)break;
		int cost[10][10];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cost[i][j] = INTBIG;
				if (i == j) cost[i][j] = 0;
			}
		}
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
		}
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) 
					cost[i][j] = cost[j][i] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
		int id = 0, sum = INTBIG;
		for (int i = 0; i < 10; i++) {
			int tmp = 0; bool flg = false;
			for (int j = 0; j < 10; j++) {
				if (i != j && cost[i][j] != INTBIG) {
					flg = true;
					tmp += cost[i][j];
				}
			}
			if (sum > tmp && flg) {
				sum = tmp; id = i;
			}
		}
		cout << id << " " << sum << endl;
	}

	return 0;
}
