#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXC 12
int N,dis[MAXC][MAXC];
bool city[MAXC];
int main()
{
	while(~scanf("%d",&N)&&N)
	{
		memset(dis,0x3F,sizeof dis);
		memset(city,0,sizeof city);
		for(int i=1;i<MAXC;i++)
			dis[i][i]=0;
		for(int i=1,a,b,c;i<=N;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			city[a]=1;city[b]=1;
			dis[a][b]=min(dis[a][b],c);
			dis[b][a]=min(dis[b][a],c);
		}
		for(int k=0;k<MAXC;k++)
		{
			if(!city[k])continue;
			for(int i=0;i<MAXC;i++)
			{
				if(!city[i])continue;
				for(int j=0;j<MAXC;j++)
				{
					if(!city[j]&&dis[i][k]<0x3F3F3F3F&&dis[k][j]<0x3F3F3F3F)continue;
					dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
				}
			}
		}
		int mn=0x7FFFFFFF,id,sum;
		for(int i=0;i<MAXC;i++)
			if(city[i])
			{
				sum=0;
				for(int j=0;j<MAXC;j++)
					if(city[j])
						sum+=dis[i][j];
				if(mn>sum)
				{mn=sum;id=i;}
			}
		printf("%d %d\n",id,mn);
	}
	return 0;
}