#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
struct edge { int cost, to; };
vector<edge> G[11];
int solve(int s)
{
    int res = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> dist(11, INF);
    dist[s] = 0;
    que.push(P(0, s));
    while(not que.empty())
    {
        P now = que.top(); que.pop();
        //if(dist[now.second] < now.first) continue;
        for(int u = 0; u < G[now.second].size(); u++)
        {
            edge e = G[now.second][u];
            if(now.first + e.cost < dist[e.to])
            {
                dist[e.to] = now.first + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    for(int i = 0; i <= 10; i++)
    {
        if(dist[i] == INF) continue;
        res += dist[i];
    }
    if(res == 0) return INF;
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        for(int i = 0; i <= 10; i++) G[i].clear();
        for(int i = 0; i < n; i++)
        {
            int from, to, cost;
            cin >> from >> to >> cost;
            G[from].push_back({cost, to});
            G[to].push_back({cost, from});
        }
        int ans = INF, u = -1;
        for(int s = 0; s <= 10; s++)
        {
            int cost = solve(s);
            if(cost < ans)
            {
                ans = cost;
                u = s;
            }
        }
        cout << u << " " << ans << endl;
    }
    return 0;
}
