def inv(a): return pow(a,P-2,P) P,N=map(int,input().split()) A=[int(x) for x in input().split()] S=input() v=A[0] for i in range(N-1): print(v,A[i+1]) if S[i]=="+": v+=A[i+1] elif S[i]=="-": v-=A[i+1] elif S[i]=="*": v*=A[i+1] elif S[i]=="/": v*=inv(A[i+1]) v%=P print(v)