#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

const int INF = 100000000;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		
		int T[10][10];

		rep(i,10){
			rep(j,10){
				if(i == j){
					T[i][j] = 0;
				}else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;

		rep(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			T[a][b] = T[b][a] = c;

			if(a + 1 > m){
				m = a + 1;
			}
			if(b + 1 > m){
				m = b + 1;
			}
		}
		
		rep(k,m){
			rep(i,m){
				rep(j,m){
					if(T[i][j] > T[i][k] + T[k][j]){
						T[i][j] = T[i][k] + T[k][j];
					}
				}
			}
		}

		int city = 0;
		int mn = INF;

		rep(i,m){
			int sum = 0;
			rep(j,m){
				sum += T[i][j];
			}
			if(mn > sum){
				mn = sum;
				city = i;
			}
		}

		cout << city << " " << mn << endl;
	}

	return 0;
}
