h,w,k=map(int,input().split()) a,*b=input().split() b=list(map(int,b)) d=0 for _ in range(h): c=int(input()) if a=="+": d+=sum([i+c for i in b])%k if a=="*": d+=sum([i*c for i in b])%k print(d%k)