N, M = map(int, input().split()) X = input().split() op = X.pop(0) B = list(map(int, X)) for i in range(N): x = int(input()) print(' '.join([str(x + b) if op == '+' else str(x * b) for b in B]))