from sys import stdin n,m = map(int,stdin.readline().rstrip().split()) li = list(map(str,stdin.readline().rstrip().split())) op = li[0] b = [int(li[i]) for i in range(1,m+1)] a = [int(stdin.readline().rstrip()) for _ in range(n)] lin = [[0 for i in range(m)]for j in range(n)] for i in range(n): for j in range(m): if op == "*": lin[i][j] = a[i]*b[j] else: lin[i][j] = a[i]+b[j] for i in lin: print(*i)