main=interact$(>>=t).lines t e=break(=='=')e#e (a,_:b)#m|c a/=c b=m++"\n"|1>0="" c=foldl1(%).map read.words b%a|a>b=a+b|a0=a*b