d={} for i in range (0,6): s=raw_input() s1=s.split() if s1[0] not in d: d[s1[0]]=[0,0] if s1[1] not in d: d[s1[1]]=[0,0] d[s1[0]][1]+=int(s1[2]) d[s1[1]][1]+=int(s1[3]) if(s1[2]>s1[3]): d[s1[0]][0]+=3 elif (s1[2]==s1[3]): d[s1[0]][0]+=1 d[s1[1]][0]+=1 else: d[s1[1]][0]+=3 for k,v in sorted(sorted(d.items(), key=lambda x:x[0]), key=lambda x: x[1], reverse=True): print k