#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define INF 1<<24
#define MAX_V 999

using namespace std;

struct Node{
	int cost;
	int depart;
	int arrival;
};

vector<Node> dat;
vector<int> cost;

void dijkstra(int s){
	int pos;
	queue<int> q;
	int t;
	cost.at(s)=0;
	
	for(vector<Node>::iterator i=dat.begin();i!=dat.end();i++){
		if((*i).depart==s){
			q.push((*i).arrival);
			cost.at((*i).arrival)=(*i).cost;
		}
	}
	
	while(!q.empty()){
		
		pos=q.front();
		q.pop();
		
		for(vector<Node>::iterator i=dat.begin();i!=dat.end();i++){			if((*i).depart==pos){
				if(cost.at((*i).arrival)==INF){
					q.push((*i).arrival);
				}
				if(cost.at((*i).arrival)>(*i).cost+cost.at(pos)){
					cost.at((*i).arrival)=(*i).cost+cost.at(pos);
				}
			}
		}
		bool f=true;
		rep(i,cost.size()){
			if(cost.at(i)==INF){
				f=false;
			}
		}
		if(f){
			break;
		}
	}
}

int main(){
	int a, b, c, num;
	Node t;
	int n;
	while(cin>>n,n){
		num=0;
		dat.clear();
		cost.clear();
		rep(i,n){
			cin>>a>>b>>c;
			t.depart =a;
			t.cost   =c;
			t.arrival=b;
			dat.push_back(t);
			t.depart =b;
			t.cost   =c;
			t.arrival=a;
			dat.push_back(t);
			num=max(num,max(a,b));
		}
		rep(k,n+1){
			cost.push_back(INF);
		}
		num++;
		int mini=-1, mCost=INF;
		rep(i,num){
			int sum=0;
			cost.clear();
			rep(k,num){
				cost.push_back(INF);
			}
			dijkstra(i);
			rep(j,num){
				sum+=cost.at(j);
			}
			if(sum<mCost){
				mCost=sum;
				mini=i;
			}
		}
		cout<<mini<<" "<<mCost<<endl;
	}
	return 0;
}