#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N;
    while (cin >> N, N) {

        auto cost = make_v(INF, 15, 15);

        for (size_t i = 0; i < 15; ++i) {
            cost[i][i] = 0;
        }

        size_t maxnode = 0;
        for (size_t i = 0; i < N; ++i) {
            size_t a, b, c; cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
            chmax(maxnode, max(a, b));
        }

        for (size_t node = 0; node <= maxnode; ++node) {
            for (size_t s = 0; s <= maxnode; ++s) {
                for (size_t g = 0; g <= maxnode; ++g) {
                    chmin(cost[s][g], cost[s][node] + cost[node][g]);
                }
            }
        }

        pair<size_t, size_t> minv = {INF, INF};
        for (size_t s = 0; s <= maxnode; ++s) {
            size_t sum = 0;
            for (size_t node = 0; node <= maxnode; ++node) {
                if (s == node) continue;
                if (cost[s][node] != INF) {
                    sum += cost[s][node];
                }
            }
            chmin(minv, make_pair(sum, s));
        }

        cout << minv.second << " " << minv.first << "\n";
    }

    return 0;
}

