#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int n;
typedef pair<int, int> P; //<to, cost>
vector<P> node[10];
queue<P> que;

int dijkstra(int s, int city);

int main(){
  while(cin >> n, n){
    int city = -1;
    for(int i = 0; i < 10; i++) node[i].clear();
    for(int i = 0; i < n; i++){
      int a, b, c;
      cin >> a >> b >> c;
      node[a].push_back(P(b, c));
      node[b].push_back(P(a, c));
      city = max(city, a);
      city = max(city, b);
    }
    P mini = P(-1, INT_MAX);
    for(int i = 0; i <= city; i++){
      int x = dijkstra(i, city);
      if(mini.s > x){
	mini.f = i;
	mini.s = x;
      }
    }

    cout << mini.f << " " << mini.s << endl;
  }
}

int dijkstra(int s, int city){
  int allcost = 0;
  for(int i = 0; i <= city; i++){
    que.push(P(s, 0));
    int mincost = INT_MAX;
    bool moved[10][10] = {{false}};
    while(!que.empty()){
      P now = que.front(); que.pop();
      if(i == now.f) mincost = min(mincost, now.s);
      else{
	for(int j = 0; j < node[now.f].size(); j++){
	  P next = node[now.f][j];
	  if(!moved[now.f][next.f]){
	    moved[now.f][next.f] = true;
	    next.s += now.s;
	    que.push(next);
	  }
	}
      }
    }
    allcost += mincost;
  }
  return allcost;
}