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: ans += sum([eval('a' + op + 'int(b)') for b in B]) ans %= K print(ans)