#include <iostream>

using namespace std;
const int INF = 2 << 35;

int main()
{

	int data[11][11];
	int n;
	int a, s, d;
	int ans, anssum;
	int sum = 0;

	while (true)
	{

		for (int i = 0; i<10; i++)
		{
			for (int k = 0; k<10; k++)
			{
				data[i][k] = INF;
			}
		}

		cin >> n;

		if (n == 0)return 0;

		for (int i = 0; i< n; ++i)
		{
			cin >> a >> s >> d;
			data[a][s] = d;
			data[s][a] = d;
		}

		for (int i = 0; i<10; i++)
		{
			for (int k = 0; k<10; k++)
			{
				for (int m = 0; m<10; m++)
				{
					if (data[i][k] > data[i][m] + data[m][k])
					{
						data[i][k] = data[i][m] + data[m][k];
						data[k][i] = data[i][m] + data[m][k];
					}
				}
			}
		}
		anssum = INF;
		for (int i = 0; i<10; ++i)
		{
			sum = 0;
			for (int k = 0; k < 10; ++k)
			{
				sum += data[i][k];
			}
			if (sum < anssum)
			{
				ans = i;
				anssum = sum;
			}
		}
		cout << ans << " " << anssum << "\n";
	}

}