#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

struct Node{
    vector<pair<int, int> > to;
    bool isDone;
    int cost;
};

const int MAX_N = 10;
Node nodes[MAX_N + 1];
int n;

void dijkstra(int start) {
    for (int i = 0; i < n; i++) {
        nodes[i].isDone = false;
        nodes[i].cost = -1;
    }
    nodes[start].cost = 0;
    while (true) {
        int min_idx = -1;
        for (int i = 0; i < n; i++) {
            if (nodes[i].isDone == true || nodes[i].cost < 0) {
                continue;
            }
            if (min_idx < 0 || nodes[i].cost < nodes[min_idx].cost) {
                min_idx = i;
            }
        }
        if (min_idx < 0) {
            break;
        }
        nodes[min_idx].isDone = true;
        for (vector<pair<int, int> >::iterator it = nodes[min_idx].to.begin(); it != nodes[min_idx].to.end(); it++) {
            int to = it->first, cost = nodes[min_idx].cost + it->second;
            if (nodes[to].cost < 0 || cost < nodes[to].cost) {
                nodes[to].cost = cost;
            }
        }
    }
}

int main() {
    while (true) {
        int m;
        cin >> m;
        if (m == 0) {
            break;
        }
        n = 0;
        for (int i = 0; i < m; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            nodes[a].to.push_back(make_pair(b, c));
            nodes[b].to.push_back(make_pair(a, c));
            n = max(n, max(a, b));
        }
        n++;
        int mini = -1, min_idx;
        for (int i = 0; i < n; i++) {
            dijkstra(i);
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += nodes[j].cost;
            }
            if (mini < 0 || sum < mini) {
                mini = sum;
                min_idx = i;
            }
        }
        cout << min_idx << " " << mini << endl;
    }
}