N,M,K=map(int,input().split()) c=input().split() t=0 for _ in range(N): a=input() t+=sum([eval(a+c[0]+b) for b in c[1:]]) print(t%K)