#include <iostream>
#include <vector>
#include <queue>
#include<algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
#define B1 1000000007
#define B2 100000007
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, w,n,r,l;
int main() {
    int n,a,b,c,m,o; 
    while (cin >> n, n) {
        m = 0;
        vector<vector<int>> G(10, vector<int>(10, 1e9));
        rep(i, 10) G[i][i] = 0;
        rep(i, n) {
            cin >> a >> b >> c;
            G[a][b] = G[b][a] = c;
            m = max(m, max(a, b));
        }m++;
        vector<vector<int>> dp;
        int ans = 1e9+7;
        rep(j, m) {
            rep(k, m) {
                rep(l, m) {
                    G[k][l] = min(G[k][l], G[k][j] + G[j][l]);
                }
            }
        }
        rep(i, m) {
            int sum = 0;
            rep(j, m) {
                sum += G[i][j];
            }
            if (sum < ans) {
                o = i; ans = sum;
            }
        }
        cout << o << " " << ans << endl;
    }
}
