N,M = [int(zz) for zz in input().split()] B = [zz for zz in input().split()] s = B[0] B = [int(zz) for zz in B[1:]] def calc(s,a,b): if s == '+': return a+b elif s == '*': return a*b tmp = [[] for _ in range(N)] for i in range(N): a = int(input()) for j in range(M): tmp[i].append(calc(s,a,B[j])) for i in range(N): [print(j,end=' ') for j in tmp[i]] print()