d={} a=0 r=lambda s:-int(s[s.rfind(' '):]) for s in sorted(open('/dev/fd/0'),key=r):a+=1;print d.setdefault(r(s),a),s.strip()