main=interact$unlines.f.map(span(':'/=)).lines f x=x#[] []#_=[] (w@(x,y):z)#v|any(`elem`(map fst$v++z))$words y=z#(v++[w])|0<1=x:f(v++z)