#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>

#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 = 1000000;

using namespace std;

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;

void shortestPath(const Graph &g, int s,
        vector<Weight> &dist, vector<int> &prev) {
    int n = g.size();
    dist.assign(n, INF); dist[s] = 0;
    prev.assign(n, -1);
    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 (prev[e.dst] != -1) continue;
        prev[e.dst] = e.src;
        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));
            }
        }
    }
}

int main(){
    int n;
    while(true){
        cin >> n;
        if(!n) break;
        Graph g(10);
        int num = 0;
        for(int i=0;i<n;++i) {
            int a,b,c;
            cin >> a >> b >> c;
            g[a].push_back(Edge(a, b, c));
            g[b].push_back(Edge(b, a, c));
            if(num < max(a,b)) num = max(a,b);
        }
        int min_index = 0;
        int min_elem = INF;
        for(int i=0;i<num;++i) {
            vector<int> dist;
            vector<int> prev;
            shortestPath(g,i,dist,prev);
            int sum = 0;
            for(int j=0;j<dist.size();++j){
                if(dist[j] < INF) sum += dist[j];
            }
            if(sum < min_elem) {
                min_elem = sum;
                min_index = i;
            }
        }
        cout << min_index << " " << min_elem << endl;
    }
}