#!/usr/bin/env python3 import operator def main(): h, w, k = map(int, input().split()) op, *b = input().split() b = list(map(int, b)) if op == '+': f = operator.add elif op == '*': f = operator.mul c = 0 for _ in range(h): a_y = int(input()) c += sum([ f(a_y, b_x) for b_x in b ]) print(c % k) if __name__ == "__main__": main()