#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;
ll dp[15][15];
const ll INF = 1e18;

int main() {
    while(1) {
        cin >> n;
        if(n == 0) break;
        for(int i = 0; i < 10; ++i) {
            for(int j = 0; j < 10; ++j) {
                if(i == j) dp[i][j] = 0;
                else dp[i][j] = INF;
            }
        }
        set<int> town;
        for(int i = 0; i < n; ++i) {
            int a, b; ll c; cin >> a >> b >> c;
            town.insert(a); town.insert(b);
            dp[a][b] = c; dp[b][a] = c;
        }
        for(int k = 0; k < 10; ++k) {
            for(int i = 0; i < 10; ++i) {
                for(int j = 0; j < 10; ++j) {
                    chmin(dp[i][j], dp[i][k]+dp[k][j]);
                }
            }
        }

        ll ans = INF;
        int anstown = 0;
        for(auto x : town) {
            ll sum = 0;
            for(auto y : town) sum += dp[x][y];
            if(ans > sum) {
                ans = sum;
                anstown = x;
            }
        }
        cout << anstown << " " << ans << endl;
    }
}
