from operator import add, mul n, _ = map(int, input().split()) opb = input().split() op = add if opb[0] == "+" else mul b = [int(i) for i in opb[1:]] for _ in range(n): a = int(input()) print(*[op(int(input()), i) for i in b])