n,*t=map(int,open(a:=0).read().split()) d=90 c=[0]*d p=[[]for i in' '*d] for i in range(n):x,y=t[i*2:-~i*2];z=y%9*10+(x+5*(y%18>8))%10;c[z]+=1;p[z]+=i+1, t=0 for i in range(d): if t