N, M = map(int, input().split()) op, *B = input().split() B = list(map(int, B)) A = [int(input()) for _ in range(N)] C = [[a * b if op == "*" else a + b for b in B] for a in A] for row in C: print(*row)