#include<iostream>
#include<cstdio>
#include<string>
#include<limits.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<set>
#include<vector>
#include<queue>
#include<set>
#include<stdlib.h>
#include<time.h>
using namespace std;
typedef long long ll;
#define inf	1000000
typedef pair<int,int>	P;
int road[10][10];
int n;
int used[10];
void init(){
	memset(used,false,sizeof(used));
	fill_n(&road[0][0],10*10,1000);
	for(int i=0;i<10;i++){
		road[i][i]=0;
	}
}

void floyd(){
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(used[k]&&used[i]&&used[j]){
					if(road[i][k]+road[k][j]<road[i][j]){
						road[j][i]=road[i][j]=road[i][k]+road[k][j];
					}
				}
			}
		}
	}
}

void solve(int &city,int &cost){
	floyd();
	for(int i=0;i<10;i++){
		if(used[i]){
			int sum=0;
			for(int j=0;j<10;j++){
				if(used[j]){
					sum+=road[i][j];
				}
			}
			if(sum<cost){
				cost=sum;
				city=i;
			}else if(sum==cost){
				city=min(city,i);
			}
		}
	}
}

int main() {
	
	int a,b,c;
	while(scanf("%d",&n)!=EOF){
		if(n==0){
			break;
		}
		init();
		while(n--){
			scanf("%d%d%d",&a,&b,&c);
			road[a][b]=road[b][a]=c;
			used[a]=used[b]=true;
		}
		int city=10,cost=INT_MAX;
		solve(city,cost);
		printf("%d %d\n",city,cost);
	}
	return 0;
}
