n,m,k=map(int,input().split()) ab=[input().split() for _ in range(m)] op=ab[0].pop(0) a,b=ab.pop(0),[i[0] for i in ab] ans=0 for i in range(m): for j in range(n): ans+=eval(a[i]+op+b[j])%k print(ans%k)