#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    vector<int> vv;
    int dp[10][10], ans[10] = {};
    rep(i, 10) rep(j, 10) dp[i][j] = i == j ? 0 : INF;
    rep(i, n) {
      int a, b, c;
      bool key1 = 1, key2 = 1;
      cin >> a >> b >> c;
      if (i == 0) {
        vv.push_back(a);
        vv.push_back(b);
      }
      rep(i, vv.size()) {
        if (vv[i] == a)
          key1 = 0;
        if (vv[i] == b)
          key2 = 0;
      }
      if (key1)
        vv.push_back(a);
      if (key2)
        vv.push_back(b);
      dp[a][b] = c;
      dp[b][a] = c;
    }
    rep(k, n) rep(i, n) rep(j, n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    rep(i, vv.size()) rep(j, vv.size()) ans[i] += dp[vv[i]][vv[j]];
    rep(i, 10) if (ans[i] == 0) ans[i] = INF;
    cout << distance(ans, min_element(ans, ans + n)) << ' '
         << ans[distance(ans, min_element(ans, ans + n))] << endl;
  }
  return 0;
}