#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef pair<int, int> P;
typedef long long int ll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;

int main(){
	while(cin >> n){
		if(n == 0) break;
		int ans[10];
		int t = 0, m = 0;
		int d[10][10];
		fill((int*)d,(int*)(d+10), INF);
		clr(ans,0);
		rep(i,10) d[i][i] = 0;
		rep(i,n){
			int temp1, temp2, temp3; scanf("%d%d%d", &temp1, &temp2, &temp3);
			d[temp1][temp2] = temp3; d[temp2][temp1] = temp3;
			if(m < temp1) m = temp1;
			if(m < temp2) m = temp2;
		}
		m++;
		rep(k,m) rep(i,m) rep(j,m) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
		rep(i,m) rep(j,m) ans[i] += d[i][j];
		for(int i = 1; i < m; i++){
			if(ans[t] > ans[i]) t = i;
		}
		cout << t << " " << ans[t] << endl;
	}
}