#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

const int MAX_V = 1e5+10;
int V,E;
vector<edge> G[MAX_V];
int d[MAX_V];

void DS(int s) {
	priority_queue<P,vector<P>,greater<P>> que;
	for(int i = 0; i <= V; i++) d[i] = INF; d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (auto e : G[v]) {
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	vector<P> vvv;
	while(1){
		for(int i = 0; i < MAX_V; i++) G[i].clear();
		V = 0;
		cin >> E;
		if(E == 0) break;
		for(int i = 0; i < E; i++){
			int f,t,c;
			cin >> f >> t >> c;
			G[f].push_back({t,c});
			G[t].push_back({f,c});
			V = max({V,f,t});
		}
		E *= 2;
		V++;
		int a1 = -1,a2 = INF;
		for(int i = 0; i < V; i++){
			DS(i);
			int sum = 0;
			for(int j = 0; j < V; j++){
				if(d[j] != INF) sum += d[j];
			}
			if(sum < a2) {a1 = i,a2 = sum;};
		}
		vvv.push_back(P(a1,a2));

		//cout << a1 << " " << a2 << endl;
	}
	for(int i = 0; i  <vvv.size(); i++){
		cout << vvv[i].first << " " << vvv[i].second << endl;
	}

	return 0;
}
