r=->{gets.split.map &:to_i} c=(2..r[][0]).map{r[]} r[] r[].map{|x|f=1,x c.map{|c|t,a,b=c f<