M(int*a){return*a-*1[&a];}n,T[9999][2];j,m,s;main(i){for(;~scanf("%d",&n);qsort(T,n,8,M),n&&printf("%d\n%d\n%d\n",1[*T],T[1][1],T[n-2][1]))for(i=n;i--;)for(scanf("%d",T[i]+1),*T[i]=0,j=4;j--;*T[i]+=m*60+s)scanf("%d%d",&m,&s);}