#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#define INF 0xffff
#define lld long long int
#define MAXN 1000002
using namespace std;

//floyd
int d[12][12];


void floyd(int x)
{
	for (int k = 0;k <= x;k++)
		for (int i = 0;i <= x;i++)
			for (int j = 0;j <= x;j++)
			{
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				d[j][i] = d[i][j];
			}
}


int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		if (n == 0)break;
		int v = 0;
		for (int i = 0;i <= 12;i++)
		{
			for (int j = 0;j <= 12;j++)
			{
				if (i == j)d[i][j] = 0;
				else d[i][j] = INF;
			}
			
		}
		for (int i = 0;i < n;i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			scanf("%d", &d[a][b]);
			d[b][a] = d[a][b];
			v = max(a, b);
		}
		floyd(v);
		int t;
		int ans=INF;
		for (int i = 0;i <= v;i++)
		{
			int tmp = 0;
			for (int j = 0;j <= v;j++)
			{
				if (i == j)continue;
				tmp += d[j][i];
			}
			if (ans > tmp)
			{
				t = i;
				ans = tmp;
			}
		}
		printf("%d %d\n", t, ans);

	}
	return 0;
}