#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    const int INF = 1 << 30;
    int dis[10][10];
    fill_n((int*)dis, 10 * 10, INF);
    for (int i = 0; i < 10; i++) {
      dis[i][i] = 0;
    }
    int m = -1;
    for (int i = 0; i < n; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      dis[a][b] = dis[b][a] = c;
      m = max(m, max(a, b) + 1);
    }
    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (dis[i][k] == INF || dis[k][j] == INF) continue;
          dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
        }
      }
    }
    int p = -1, q = 1 << 30;
    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = 0; j < m; j++) {
        sum += dis[i][j];
      }
      if (sum < q) p = i, q = sum;
    }
    cout << p << " " << q << endl;
  }

  return 0;
}
