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