#include <iostream>
#include <vector>
#include <string.h>
#define INF 999999999
using namespace std;

struct edge
{
	int From;
	int To;
	int Dist;
};

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector< vector<int> > D(10, vector<int>(10));
		vector<edge> Edge(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Edge[i].From >> Edge[i].To >> Edge[i].Dist;
		}
		int city_num = 0;
		for(int i = 0; i < n; ++i)
		{
			city_num = max(city_num, Edge[i].From);
			city_num = max(city_num, Edge[i].To);
		}
		city_num++;
		for(int i = 0; i < city_num; ++i)
		{
			for(int j = 0; j < city_num; ++j)
			{
				D[i][j] = INF;
			}
		}
		for(int i = 0; i < n; ++i)
		{
			D[i][i] = 0;
			D[Edge[i].From][Edge[i].To] = Edge[i].Dist;
			D[Edge[i].To][Edge[i].From] = Edge[i].Dist;
		}
		
		bool update = true;
		while(update)
		{
			update = false;
			for(int i = 0; i < city_num; ++i)
			{
				for(int j = 0; j < city_num; ++j)
				{
					for(int k = 0; k < city_num; ++k)
					{
						if(D[i][k] != INF && D[k][j] != INF && (D[i][k] + D[k][j] < D[i][j]))
						{
							D[i][j] = D[i][k] + D[k][j];
							update = true;
						}
					}
				}
			}
		}
		int min = INF;
		int index = 0;
		for(int i = 0; i < city_num; ++i)
		{
			int sum = 0;
			for(int j = 0; j < city_num; ++j)
			{
				sum += D[i][j];
			}
			if(min > sum)
			{
				min = sum;
				index = i;
			}
		}
		cout << index << " " << min << endl;
	}
}

int main()
{
	solve();
	return(0);
}