n,m,k = map(int,input().split()) op_B = input().split() op = op_B[0] B = list(map(int,op_B[1:])) A = [int(input()) for i in range(n)] result = 0 for ai in A: result2 = 0 for bi in B: result2+=eval(str(ai)+op+str(bi)) result+=result2 print(result%k)