
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define vc vector

const int INF = 100000000;

using namespace std;


int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)break;
		vector<vector<int>> v(10, vector<int>(10, INF));

		int maxnum=0;
		rep(i, 0, n) {
			int from, to, cost;
			cin >> from >> to >> cost;
			v[from][to] = cost;
			v[to][from] = cost;

			if (maxnum < to)maxnum = to;
			v[i][i] = 0;
		}
		maxnum++;

		rep(i, 0, maxnum) {
			rep(j, 0,maxnum) {
				rep(k, 0, maxnum) {
					v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
				}
			}
		}

		/*rep(i, 0, maxnum) {
			rep(j, 0, maxnum) cout << i << " " << j << " " << v[i][j] << endl;
		}*/

		int ans = INF, ansnum;
		rep(i, 0, maxnum) {
			int sum = 0;
			rep(j, 0, maxnum) {
				if(i!=j && v[i][j]!=INF)sum += v[i][j];
			}
			if (ans > sum) {
				ans = sum;
				ansnum = i;
			}
		}

		cout << ansnum << " " << ans << endl;
	}
	
	
	return 0;
}