from sys import stdin def main(): #入力 readline=stdin.readline N,M=map(int,readline().split()) B=readline().split() op=B.pop(0) B=list(map(int,B)) A=[0]*N for i in range(N): A[i]=int(readline()) res=[[0]*M for _ in range(N)] for i in range(N): for j in range(M): if op=="+": res[i][j]=A[i]+B[j] elif op=="*": res[i][j]=A[i]*B[j] for i in range(N): print(*res[i]) if __name__=="__main__": main()