#coding: utf-8 N, M, K = map(int, input().split()) op, *B = input().split() A = [] for i in range(N): A.append(str(input())) ans = [[0 for _ in range(M)] for _ in range(N)] ans = 0 for i in range(N): for j in range(M): ans += eval(A[i]+"%{}".format(K) + op + B[j]+"%{}".format(K)) ans %= K print(ans % K)