for tc in range(1,int(input())+1):
arr=list(input().split())
chk=[]
for i in arr:
if i.isalnum():
chk.append(int(i))
elif i=='.':
if len(chk)>1:
chk=['error']
else:
if len(chk)<2:
chk=['error']
break
else:
x=chk.pop()
y=chk.pop()
if x<y:
x,y=y,x
if i=='+':
chk.append(x+y)
elif i=='-':
chk.append(x-y)
elif i=='*':
chk.append(x*y)
elif i=='/':
chk.append(x//y)
elif i=='%':
chk.append(x%y)
print(f'#{tc} {chk[0]}')