#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define scanf scanf_s

int n;
int cost[11][11];
int main()
{
	while (cin >> n,n)
	{
		REP(i, 11)REP(j, 11) cost[i][j] = INF;
		REP(i, 11) cost[i][i] = 0;
		int city = 0;
		REP(i, n)
		{
			int a, b, c;
			cin >> a >> b >> c;
			city = max(city, max(a, b));
			cost[a][b] = c;
			cost[b][a] = c;
		}
		city++;
		REP(i, city)REP(j, city)REP(k, city)
		{
			cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
		}
		int lcost[11] = {};
		REP(i, city)
		{
			REP(j, city) lcost[i] += cost[i][j];
		}
		int ansc = INF;
		int ans;
		REP(i, city)
		{
			if (ansc > lcost[i])
			{
				ansc = lcost[i];
				ans = i;
			}
		}
		cout << ans << " " << ansc << endl;
	}
	return 0;
}