//2013/11/15(Fri)

#include <iostream>
using namespace std;
int main()
{
	
	while(true){
		int n;
		int a,b,c;
		int INF = 12001;
		int time[45][45];
		int dtime[45][45]={0};
		int sam[10] = {0};
		int min=12000,imin=0;
		cin >> n;
		if(n==0)
			break;
		for(int i=0; i<45; i++)
			for(int j=0; j<45; j++){
				if(i==j)
					time[i][j] = 0;
		
				else
					time[i][j] = INF;
			}

		for(int i=0; i<n; i++){
			cin >> a >> b >> c;
			time[a][b] = c;
			time[b][a] = c;
		}

		for(int i=0; i<45; i++)
			for(int j=0; j<45; j++)
				dtime[i][j] = time[i][j];

		for(int h=0; h<b+1; h++)
			for(int i=0; i<b+1; i++)
				for(int j=0; j<b+1; j++)
					if(dtime[i][j] > dtime[i][h] + dtime[h][j])
						dtime[i][j] = dtime[i][h] + dtime[h][j];
				
		
		for(int i=0; i<b+1; i++)
			for(int j=0; j<b+1; j++)
				sam[i] += dtime[i][j];


		for(int i=0; i<b+1; i++)
			if(sam[i] < min){
				min = sam[i];
				imin = i;
			}
			cout << imin << ' ' << min << endl;
	}
	return 0;
	
}