#include <vector>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
#include <string.h>
#include <stdio.h>

typedef long long ll;
using namespace std;

typedef vector<vector<int>> graph_t;
const int INF = 1e9+1;

pair<int, int> solve(vector<tuple<int, int, int>> roads)
{
	graph_t g;
	const int N = 10;
	g.resize(N);
	for (int i = 0; i < N; i++) {
		g[i].resize(N, INF);
		g[i][i] = 0;
	}
	for (auto i = roads.begin(); i != roads.end(); ++i) {
		int s = get<0>(*i);
		int t = get<1>(*i);
		int d = get<2>(*i);
		g[s][t] = d;
		g[t][s] = d;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}
	}
	int ans = INF;
	int index = -1;
	for (int i = 0; i < N; i++) {
		int s = 0;
		for (int j = 0; j < N; j++) {
			if (i == j || g[i][j] >= INF)
				continue;
			s += g[i][j];
		}
		if (ans > s && s > 0) {
			ans = s;
			index = i;
		}
	}
	return make_pair(index, ans);
}

void solve_stdio()
{
	while (true) {
		int n;
		if (!(cin >> n))
			break;
		if (n == 0)
			break;
		vector<tuple<int, int, int>> roads;
		for (int i = 0; i < n; i++) {
			int s, t, d;
			cin >> s >> t >> d;
			roads.emplace_back(s, t, d);
		}
		int index;
		int ans;
		tie(index, ans) = solve(roads);
		cout << index << " " << ans << endl;
	}
}

int main()
{
	solve_stdio();
}
