n, m = map(int, input().split()) opb = list(map(str, input().split())) op = opb[0] b = [int(x) for x in opb[1:]] a = [int(input()) for _ in range(n)] ans = [[] for _ in range(n)] for i in range(n): for j in range(m): if op == '+': ans[i].append(a[i]+b[j]) else: ans[i].append(a[i]*b[j]) for i in range(n): print(*ans[i])