#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;


typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

vector<Weight> dijkstra2(const Graph &g, int s) {
  int n = g.size();
  vector<Weight> dist(n, INF);
  dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return dist;
}


int main() {
  int n;
  while(cin >> n,n) {
    Graph g(10);
    int m = 0;
    while(n--) {
      int a,b,c;
      cin >> a >> b >> c;
      g[a].push_back(Edge(a,b,c));
      g[b].push_back(Edge(b,a,c));
      m = max(max(m, a), b);
    }
    m++;
    g.resize(m);
    int res, mi = INF;
    REP(i, m) {
      vector<int> d = dijkstra2(g, i);
      int sum = 0;
      REP(j, m)
        sum += d[j];
      if (mi > sum) {
        mi = sum;
        res = i;
      }
    }
    cout << res << " " << mi << endl;
  }
}