#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 50
#define INF 0x3FFFFFFF
using namespace std;
int f[MAXN][MAXN];
int n,m;
int main(){
    SF("%d",&n);
    while(n){
        int x,y,v;
        for(int i=0;i<=9;i++)
            for(int j=0;j<=9;j++)
                f[i][j]=INF;
        for(int i=1;i<=n;i++){
            SF("%d%d%d",&x,&y,&v);
            f[x][y]=min(f[x][y],v);
            f[y][x]=min(f[y][x],v);
        }
        for(int i=0;i<=9;i++)
            for(int j=0;j<=9;j++)
                for(int k=0;k<=9;k++)
                    if(i!=j&&k!=j&&k!=i)
                        f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
        int ans=-1,bestid;
        for(int i=0;i<=9;i++){
            int ans1=-1;
            for(int j=0;j<=9;j++){
                if(f[i][j]==INF||i==j)
                    continue;
                if(ans1==-1)
                    ans1=0;
                ans1+=f[i][j];
                //PF("(%d %d %d)\n",i,j,f[i][j]);
            }
            if(ans1!=-1&&(ans1<ans||ans==-1)){
                bestid=i;
                ans=ans1;
            }
        }
        PF("%d %d\n",bestid,ans);
        SF("%d",&n);
    }
}