#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int n, maxcity = 0, d[12][12], sum[12], ans = INF, anstown;

int main() {
    while (cin >> n,n) {
        for (int i = 0; i <= 11; i++) {
            for (int j = 0; j <= 11; j++) {
                if (i == j)d[i][j] = 0;
                else d[i][j] = INF;
            }
        }
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            d[a][b] = c;
            d[b][a] = c;
            maxcity = max(maxcity, b);
        }
        for (int k = 0; k <= maxcity; k++) {
            for (int i = 0; i <= maxcity; i++) {
                for (int j = 0; j <= maxcity; j++) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        for (int i = 0; i <= maxcity; i++) {
            for (int j = 0; j <= maxcity; j++) {
                sum[i] += d[i][j];
            }
        }
        for (int i = 0; i <= maxcity; i++) {
            if (ans > sum[i]) {
                ans = sum[i];
                anstown = i;
            }
        }
        cout << anstown << ' ' << ans << endl;
    }
    return 0;
}