N,M,K=map(int,input().split()) op,*B=input().split() A=[] for i in range(N): A.append(input()) _sum=0 for a in A: for b in B: _sum += eval(a+op+b) print(_sum % K)