#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

const int INF = 1e+8;

typedef struct edge_def {
	int to;
	int cost;
	edge_def(int _to, int _cost) {to = _to; cost = _cost;}
} edge;

typedef pair<int, int> P;

int V, E;
const int MAX_V = 10;
vector<edge> G[MAX_V];	//[i] : fromを表す
int d[MAX_V];

void dijkstra(int s) {
	int i;
	priority_queue<P, vector<P>, greater<P> > q;

	for (i=0; i<V; i++) d[i] = INF;
	d[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top();
		q.pop();
		int v = p.second;

		if (d[v] < p.first) continue;

		for (i=0; i<(int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int i, j;
	int total;
	int minT;

	while (1) {
		scanf("%d ", &E);
		if (!E) break;

		V = 0;
		for (i=0; i<E; i++) {
			int ef, et, ec;
			scanf("%d%d%d ", &(ef), &(et), &(ec));
			G[ef].push_back(edge(et, ec));
			G[et].push_back(edge(ef, ec));
			V = max(V, ef);	
			V = max(V, et);	
		}
		V++;

		total = INF;
		minT = INF;
		for (i=0; i<V; i++) {
			dijkstra(i);

			int sum = 0;
			for (j=0; j<V; j++)
				sum += d[j];

			if (sum < total) {
				total = sum;
				minT = i;
			} else if (sum == total && i < minT)
				minT = i;
		}

		printf("%d %d\n", minT, total);
	}	

	return 0;
}