#include <cstdio>
#include <algorithm>
using namespace std;
static const int MAX = 10;
static const int INFTY = 1000000;
int V;
int d[MAX][MAX];


void floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (d[i][k] == INFTY) continue;
            for (int j = 0; j < V; j++) {
                if (d[k][j] == INFTY) continue;
                d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int sum, minv=INFTY, mini;
    for (int i = 0; i < V; i++) {
        sum = 0;
        for (int j = 0; j < V; j++) sum += d[i][j];
        if (sum < minv) { minv = sum, mini = i; }
    }
    printf("%d %d\n", mini, minv);
}



int main() {
    int E, source, target, cost;
    for(; ;) {
        std::scanf("%d", &E);
        if (E == 0) break;
        for (int i = 0; i < 10; i++) fill(d[i], d[i]+10, INFTY);
        V = 0;
        for (int i = 0; i < E; i++) {
            std::scanf("%d %d %d", &source, &target, &cost);
            d[source][target] = d[target][source] = cost;
            V = max(V, max(source, target));
        }
        V++;
        for (int i = 0; i < V; i++) d[i][i] = 0;
        floyd();
    }
    return 0;
}

