#include <algorithm>
#include <climits>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int n, a, b, c;
	while (cin >> n, n) {
		vector<vector<pair<int, int>>> d(10);
		for (int i = 0; i < n; ++i) {
			cin >> a >> b >> c;
			d[a].emplace_back(b, c);
			d[b].emplace_back(a, c);
		}
		vector<pair<int, int>> ans(10);
		for (int i = 0; i < 10; ++i) {
			priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> e;
			e.emplace(0, i);
			vector<bool> f(10);
			vector<int> g(10, INT_MAX);
			g[i] = 0;
			while (!e.empty()) {
				pair<int, int> h = e.top();
				e.pop();
				f[h.second] = true;
				for (pair<int, int>& j : d[h.second]) {
					if (!f[j.first]) {
						if (g[h.second] + j.second < g[j.first]) {
							g[j.first] = g[h.second] + j.second;
							e.emplace(g[j.first], j.first);
						}
					}
				}
			}
			for_each(g.begin(), g.end(), [](int& a) { if (INT_MAX == a) a = 0; });
			ans[i] = make_pair(accumulate(g.begin(), g.end(), 0), i);
		}
		for_each(ans.begin(), ans.end(), [](pair<int, int>& a) { if (0 == a.first) a.first = INT_MAX; });
		sort(ans.begin(), ans.end());
		cout << ans.front().second << ' ' << ans.front().first << endl;
	}
}
