#include <iostream>
#define INF 1000000000
using namespace std;

int main() {
	for (;;)
	{
		int edge[11][11];
		int city = 0;
		for (int i = 0;i < 11;i++) 
		{
			for (int j = 0;j < 11;j++)
			{
				if(i == j)
				{
					edge[i][i] = 0;
					continue;
				}
				edge[i][j] = INF;
			}
		}
		int n;
		cin >> n;
		if (n == 0) break;
		for (int i = 0;i < n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			edge[a][b] = c;
			edge[b][a] = c;
 			city = max (max(a,b)+1,city);
		}
		for (int i = 0;i < city;i++)
		{
			for (int j = 0;j < city;j++)
			{
				for (int k = 0;k < city;k++)
				{
					edge[i][k] = min(edge[i][k],edge[i][j]+edge[j][k]);
				}
			}
		}
		//??????????????§edge?????????????????¢?????\??£?????????(??????????????§?????????)
		int min = INF;
		int minCity;
		for (int i = 0;i < city;i++)
		{
			int sum = 0;
			for (int j = 0;j < city;j++)
			{
				if (i == j) continue;
				sum += edge[i][j];
			}
			if (sum < min)
			{
				min  = sum;
				minCity = i;
			}
		}
		cout << minCity << " " << min << endl;
	}
	return 0;
}