main@m=getLine>>=f.words>>m f[x,y]=print$head[z|z<-[2..],x#10==y#z] a#b=foldl1((+).(*b))[read[c]|c<-a]