from functools import reduce N,M,K = map(int,input().split()) op,*B = input().split() A = [int(input()) for i in range(N)] ans = 0 for a in A: row = [eval('a' + op + 'int(b)') for b in B] ans += reduce(lambda a,b: (a+b)%K, row) ans %= K print(ans)