while read a b c do u[a]?a=u[a],_:a r[y=_,a=b,y-_?u[y]=a,0:1]=$c done echo $r