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