n,m,k=map(int,input().split()) ab=[input().split() for _ in range(m)] op=ab[0].pop(0) b,a=[int(i) for i in ab.pop(0)],[int(i[0]) for i in ab] if op=='+': print((sum(b)*n+sum(a)*m)%k) else: print(sum(a)*sum(b)%k)