import re,os for(s,n,k)in re.findall('(\D*)(\d*)x(\^.)?',os.read(0,9**9)):p=hash(k)%5;os.write(1,s+`int(n)*-~p`+("x^%d"%p)[:p*p])