import re for s,c,e in re.findall(r'(\D*)(\d*)x(\^.)?',open(0).read()):e=hash(e)%5;print(end=s+str(int(c)*-~e)+('x^%d'%e)[:e*e])