#include<iostream>

#define TOWN_MAX 10
#define ROAD_MAX 45
#define INF 1000000000

int  distances[TOWN_MAX][TOWN_MAX];

int solve(int);

int main(int argc, char const* argv[]) {
    int n;

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {

    for (int i = 0; i < TOWN_MAX; i++)
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = (i == j) ? 0 : INF;

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][dest] = cost;
        distances[dest][src] = cost;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost = INF;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        int sum_cost = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            if (distances[i][j] != INF) sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost && sum_cost != 0) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost << std::endl;

    return 0;
}