#include <stdio.h>
#include <stdlib.h>
int father[102];
struct road
{
int u,v,len;
}path[5001];
int compare(const void*a,const void*b);
int find(int x);
void Union(int x,int y);
int main()
{
int m,n,i,pv,pu,s,t=1;
while(scanf("%d",&n)!=EOF&&n!=0)
{
m=(n-1)*n/2;
for(i=1;i<=n;i++)
father[i]=i;
for(i=0;i<m;i++)
{
scanf("%d %d %d",&path[i].u,&path[i].v,&path[i].len);
}
qsort(path,m,sizeof(path[0]),compare);
for(s=i=0;i<m;i++)
{
pv=find(path[i].u);
pu=find(path[i].v);
if(pv!=pu)
{
s=s+path[i].len;
Union(pv,pu);
}
}
printf("%d\n",s);
}
return 0;
}
int find(int x)
{
if(x!=father[x])
father[x]=find(father[x]);
return father[x];
}
void Union(int x,int y)
{
int a=find(x);
int b=find(y);
if(a!=b)
father[b]=a;
}
int compare(const void*a,const void*b)
{
return (*(road*)a).len-(*(road*)b).len;
}