#include <bits/stdc++.h>
using namespace std;

int n;
const int INF = 1e9;

struct edge {
	int to, tm;
};

int main()
{
	cin >> n;

	while (n > 0) {
		int a, b, c, m, mc, md, t = 0;
		int d[10];
		typedef pair<int, int> P;
		vector<edge> G[10];

		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			
			edge e;
			e.to = b;
			e.tm = c;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);

			t = max(t, max(a, b));
		}

		md = INF;

		for (int i = 0; i <= t; i++) {
			mc = 0;
			fill(d, d + 10, INF);
			d[i] = 0;

			priority_queue<P, vector<P>, greater<P>> Q;
			Q.push(P(0, i));

			while (!Q.empty()) {
				P p = Q.top();
				Q.pop();

				int u = p.second;
				if (d[u] < p.first)
					continue;

				for (edge e : G[u]) {
					if (d[e.to] > d[u] + e.tm) {
						d[e.to] = d[u] + e.tm;
						Q.push(make_pair(d[e.to], e.to));
					}
				}
			}

			for (int i = 0; i <= t; i++)
				if(d[i] < INF)
					mc += d[i];

			if (mc < md) {
				m = i;
				md = mc;
			}
		}

		cout << m << " " << md << endl;
		cin >> n;
	}
}

